Skip to content

Instantly share code, notes, and snippets.

@bsoist
Created September 26, 2013 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsoist/6714869 to your computer and use it in GitHub Desktop.
Save bsoist/6714869 to your computer and use it in GitHub Desktop.
Digging through Disqus API
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