Skip to content

Instantly share code, notes, and snippets.

@json-m json-m/spaceislit.py
Created Dec 13, 2018

Embed
What would you like to do?
top 5 posts for /r/space
import requests
import json
count = 0
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36'
}
r = requests.get('https://www.reddit.com/r/space/top.json', headers=headers)
posts = json.loads(r.text)
print('--- /r/space top posts')
print('----------------------')
for post in posts['data']['children']:
print('[%s] %s' % (post['data']['score'], post['data']['title']))
print('URL: ' + post['data']['url'])
print('Comments: ' + 'https://reddit.com' + post['data']['permalink'])
print('----------------------')
count += 1
if count > 4:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.