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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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.