Skip to content

Instantly share code, notes, and snippets.

@heyalexej
Created August 11, 2015 09:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heyalexej/c981488c73c32901f410 to your computer and use it in GitHub Desktop.
Save heyalexej/c981488c73c32901f410 to your computer and use it in GitHub Desktop.
Quick, Dirty & Wonky Sub Tracker for Chris
import requests
import time
import json
headers = {'User-Agent': 'android:subgrowth:v0.1 (by /u/twelvis)'}
def getit(subreddit):
r = requests.get(
'http://www.reddit.com/r/' +
subreddit.strip() +
'/about.json', timeout=30, headers=headers)
if 200 != r.status_code:
pass
try:
block = json.loads(r.text)
except Exception as ex:
print ex
return False
return block
def subinfo(subreddit):
j = getit(subreddit)
print j
if j['data']:
readers = j['data']['subscribers']
active = j['data']['accounts_active']
# construct the json object
values = {'timestamp': int(time.time()),
'readers': readers,
'active': active,
'sub': subreddit
}
return json.dumps(values)
else:
pass
if __name__ == '__main__':
while True:
print subinfo('dataisbeautiful')
time.sleep(300) # sleep tight in seconds
# track multiple subs
# if __name__ == '__main__':
# subs = ['dataisbeautiful',
# 'entrepreneur',
# 'seo']
# while True:
# time.sleep(300)
# for sub in subs:
# print subinfo(sub)
@chrisdietr
Copy link

thx digger!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment