Created
July 31, 2014 05:40
-
-
Save tessus/967c9b903e58d974907d to your computer and use it in GitHub Desktop.
retrieve TekSavvy data usage via API key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/local/bin/python | |
import httplib, json | |
APIKEY = "YOUR_API_KEY_HERE" | |
headers = {"TekSavvy-APIKey": APIKEY} | |
conn = httplib.HTTPSConnection("api.teksavvy.com") | |
conn.request('GET', '/web/Usage/UsageSummaryRecords?$filter=IsCurrent%20eq%20true', '', headers) | |
response = conn.getresponse() | |
jsonData = response.read() | |
data = json.loads(jsonData) | |
pd = data["value"][0]["OnPeakDownload"] | |
pu = data["value"][0]["OnPeakUpload"] | |
opd = data["value"][0]["OffPeakDownload"] | |
opu = data["value"][0]["OffPeakUpload"] | |
sd = data["value"][0]["StartDate"] | |
ed = data["value"][0]["EndDate"] | |
print "%s %s %s %s" % (pd, pu, opd, opu) |
@tessus Kind of new to this... How would I convert that to javascript to display on a webpage?
@davidbgeek Sorry, I didn't get an email when you commented. I don't know, I'm not a js person. But you would have to parse the response from the API call. But you can also use PHP for this and with that I could help.
@Humanoid - I realize this is old, but perhaps this will help someone. Here is the jQuery way. However, I don't think it will work due to CORS access control. I believe this must be done server-side - which can be done in Node if you need JS, though don't use jQuery for that use-case.
var settings = {
"async": true,
"crossDomain": true,
"url": "https://api.teksavvy.com/web/Usage/UsageSummaryRecords?$filter=IsCurrent%20eq%20true",
"method": "GET",
"headers": {
"TekSavvy-APIKey": "YOUR-API-KEY",
"Cache-Control": "no-cache"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this. I will try it out.