Skip to content

Instantly share code, notes, and snippets.

@db0company
Created March 7, 2016 23:09
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 db0company/1f2ef8a70721f851ac44 to your computer and use it in GitHub Desktop.
Save db0company/1f2ef8a70721f851ac44 to your computer and use it in GitHub Desktop.
Get the total number of comments in a Disqus forum
import urllib2, json
api_key = 'your_disqus_api_key'
forum = 'your_forum_shortname'
f = urllib2.urlopen('https://disqus.com/api/3.0/forums/listThreads.json?api_key=' + api_key + '&forum=' + forum + '&limit=100')
data = json.loads(f.read())
total = 0
for thread in data['response']:
total += thread['posts']
i = 1
threads = 100
while 'next' in data['cursor']:
print 'next %s : %s (%s %s)' % (i, data['cursor']['next'], str(threads), str(total))
f = urllib2.urlopen('https://disqus.com/api/3.0/forums/listThreads.json?api_key=' + api_key + '&forum=' + forum + '&limit=100&cursor=' + data['cursor']['next'])
data = json.loads(f.read())
for thread in data['response']:
threads += 1
total += thread['posts']
i += 1
print 'threads %s total comments %s' % (threads, total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment