Created
April 28, 2019 12:59
-
-
Save jtoomim/dfbb61284c0a38828d3eabb4228e2efb to your computer and use it in GitHub Desktop.
Quick script for checking how many comments occurred in a month on a subreddit using pushshift.io
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 urllib.request, json | |
# https://api.pushshift.io/reddit/comment/search/?subreddit=btc&aggs=subreddit&size=0&after=2015-09-01&before=2016-01-01&author=!automoderator | |
doc_counts = {} | |
sub = 'btc' | |
for y in range(2011, 2020): | |
for m in range(1, 13): | |
if m == 12: | |
nm = 1 # next month | |
ny = y+1 | |
else: | |
nm = m+1 | |
ny = y | |
url = "https://api.pushshift.io/reddit/comment/search/?subreddit=%s&aggs=subreddit&size=0&after=%i-%02i-01&before=%i-%02i-01&author=!automoderator" % (sub, y, m, ny, nm) | |
with urllib.request.urlopen(url) as response: | |
html = response.read().decode('utf-8') | |
j = json.loads(html) | |
try: | |
doc_counts[(y, m)] = j['aggs']['subreddit'][0]['doc_count'] | |
except: | |
doc_counts[(y, m)] = 0 | |
print("%i-%02i: %i" % (y, m, doc_counts[(y, m)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment