Skip to content

Instantly share code, notes, and snippets.

@belak
Created March 15, 2014 04:22
Show Gist options
  • Save belak/9561792 to your computer and use it in GitHub Desktop.
Save belak/9561792 to your computer and use it in GitHub Desktop.
import requests
import gspread
gc = gspread.login('[email protected]', 'password')
wks = gc.open('Reddit Analysis Data').sheet1
# Grab the hot topics
r = requests.get("http://www.reddit.com/hot.json?limit=50")
j = r.json()
cols = ['title', 'author', 'over_18', 'url', 'permalink', 'created_utc', 'subreddit', 'num_comments', 'ups', 'downs', 'score']
# Loop through results
row = 3
for post in j['data']['children']:
col = 0
print(post['data']['title'])
row_data = wks.range('A%d:K%d' % (row, row))
for col_name in cols:
row_data[col].value = post['data'][col_name]
col += 1
row_data[4].value = 'http://www.reddit.com'+row_data[4].value
wks.update_cells(row_data)
row += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment