Created
September 26, 2013 14:18
-
-
Save bsoist/6714869 to your computer and use it in GitHub Desktop.
Digging through Disqus API
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, urllib2, time | |
API_KEY = "" | |
BASE_URL = "https://disqus.com/api/3.0/" | |
CURSOR = "" | |
FORUM = "" | |
DOMAIN = "" | |
threads = [] | |
years = {} | |
def get(req,**kwargs): | |
return json.load(urllib2.urlopen("%s%s?%s" % (BASE_URL, req, "&".join(["%s=%s" % (k,v) for k,v in kwargs.items()])))) | |
def getThreads(**kwargs): | |
return get("threads/list.json", **kwargs) | |
while True: | |
try: | |
data = getThreads(api_key=API_KEY,forum=FORUM,cursor=CURSOR,limit="100") | |
CURSOR = data['cursor']['next'] | |
except urllib2.HTTPError as e: | |
CURSOR = False | |
print e.msg | |
time.sleep(15*60) | |
continue | |
for response in data['response']: | |
if not response['link']: continue | |
if DOMAIN in response['link']: | |
threads.append(response) | |
if not CURSOR: break | |
for thread in threads: | |
year = thread['createdAt'].split('-')[0] | |
if year not in years: years[year] = 0 | |
years[year] += thread['posts'] | |
for year in sorted(years.keys()): | |
print year, years[year] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment