Guest User

TFB Subscriber counter

a guest
Jan 28th, 2016
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import urllib2
  2. import json
  3. import time
  4. import time
  5. newjsonobject = {"data":[]}
  6.  
  7. while True:
  8. x = urllib2.urlopen("https://www.googleapis.com/youtube/v3/channels?part=statistics&id=UC0v-tlzsn0QZwJnkiaUSJVQ&key={YOUR_KEY_HERE}").read()
  9. parsed_json = json.loads(x)
  10. x.close()
  11. print parsed_json["items"][0]["statistics"]["subscriberCount"]
  12. entry = {'Time': int(time.time()), 'SubscriberCount': parsed_json["items"][0]["statistics"]["subscriberCount"]}
  13. newjsonobject["data"].append(entry)
  14. with open('data.json', 'w') as newjsonfile:
  15. json.dump(newjsonobject, newjsonfile)
  16. time.sleep(2) # Delay for 2 seconds
Advertisement
Add Comment
Please, Sign In to add comment