Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib2
- import json
- import time
- import time
- newjsonobject = {"data":[]}
- while True:
- x = urllib2.urlopen("https://www.googleapis.com/youtube/v3/channels?part=statistics&id=UC0v-tlzsn0QZwJnkiaUSJVQ&key={YOUR_KEY_HERE}").read()
- parsed_json = json.loads(x)
- x.close()
- print parsed_json["items"][0]["statistics"]["subscriberCount"]
- entry = {'Time': int(time.time()), 'SubscriberCount': parsed_json["items"][0]["statistics"]["subscriberCount"]}
- newjsonobject["data"].append(entry)
- with open('data.json', 'w') as newjsonfile:
- json.dump(newjsonobject, newjsonfile)
- time.sleep(2) # Delay for 2 seconds
Advertisement
Add Comment
Please, Sign In to add comment