Skip to content

Instantly share code, notes, and snippets.

@tessus
Created July 31, 2014 05:40
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tessus/967c9b903e58d974907d to your computer and use it in GitHub Desktop.
Save tessus/967c9b903e58d974907d to your computer and use it in GitHub Desktop.
retrieve TekSavvy data usage via API key
#!/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)
@drew7721
Copy link

Thank you for this. I will try it out.

@hmnd
Copy link

hmnd commented Jun 30, 2016

@tessus Kind of new to this... How would I convert that to javascript to display on a webpage?

@tessus
Copy link
Author

tessus commented Oct 13, 2016

@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.

@matthabermehl
Copy link

matthabermehl commented Jul 3, 2018

@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