Created
March 7, 2016 23:09
-
-
Save db0company/1f2ef8a70721f851ac44 to your computer and use it in GitHub Desktop.
Get the total number of comments in a Disqus forum
This file contains 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 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