Created
September 14, 2014 18:02
-
-
Save km09/ce16964646aab45e1380 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
import json | |
import urllib2 | |
import StringIO | |
import gzip | |
from time import sleep | |
from os import system | |
import platform | |
oldUsers = {} | |
while True: | |
if platform.system() == "Windows": | |
system("cls") | |
else: | |
system("clear") | |
data = urllib2.urlopen("http://tracker.archiveteam.org/verizon/stats.json").read() | |
# Data is gzipped | |
data = StringIO.StringIO(data) | |
gzipper = gzip.GzipFile(fileobj=data) | |
data = gzipper | |
jsonData = json.load(data) | |
size = jsonData["downloader_bytes"] | |
count = jsonData["downloader_count"] | |
users = {} | |
for user in size: | |
users[user] = {"size": size[user]} | |
for user in count: | |
users[user]["count"] = count[user] | |
if oldUsers != {}: | |
i = 0 | |
total = 0 | |
for key in sorted(size, key=size.get, reverse=True): | |
try: | |
if count[key]-oldUsers[key]["count"] > 0: | |
print "%s: %s MB, %s" % (key, (size[key]-oldUsers[key]["size"]) >> 20, count[key]-oldUsers[key]["count"]) | |
total = total + (count[key]-oldUsers[key]["count"]) | |
i += 1 | |
except: | |
print "New user found, name: %s" % key | |
print "Total number of jobs done in the last minute: %s" % total | |
else: | |
print "Start, refreshing in 60 seconds!" | |
oldUsers = users | |
sleep(60) # Sleep for 60 seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment