Created
June 5, 2015 15:17
-
-
Save sgricci/4c4474d4ec8373779036 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
import pygal | |
import requests | |
import simplejson as json | |
from timelib import strtodatetime | |
import datetime | |
url = 'http://api.whatpulse.org/pulses.php?user=sgricci&format=json' | |
if __name__ == "__main__": | |
res = requests.get(url) | |
datum = {} | |
results = json.loads(res.text) | |
now = datetime.datetime.now() | |
total = 0 | |
for id in results: | |
result_date = strtodatetime(results[id]['Timedate'].encode('utf-8')) | |
diff = result_date - now | |
diff_key = abs(round(diff.seconds/3600)) + (diff.days*24) | |
diff_key = abs(diff_key - 8) | |
if diff_key > 36 or diff_key < 0: | |
continue | |
print('%d - %s' % (round(diff.seconds/3600), result_date)) | |
#print("Hour: %s - Keys: %s" % (diff_key, results[id]['Keys'])) | |
if diff_key not in datum: | |
datum[diff_key] = 0 | |
datum[diff_key] = datum[diff_key] + int(results[id]['Keys']) | |
total = int(results[id]['Keys']) + total | |
#print(results[id]) | |
print(datum) | |
print(max(datum.keys(), key=int)) | |
chart = pygal.Line(fill=True) | |
chart.title = "Key Frequency" | |
chart.x_labels = map(str, range(max(datum.keys(), key=int)-1)) | |
chart.add('Keys', list(datum.values())) | |
chart.render_to_file('keys.svg') | |
print('TOTAL KEYS: %d' % total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment