Skip to content

Instantly share code, notes, and snippets.

@odunola499
Last active September 10, 2022 13:25
Show Gist options
  • Save odunola499/176e8d78eafcbe66c40782a238df64fd to your computer and use it in GitHub Desktop.
Save odunola499/176e8d78eafcbe66c40782a238df64fd to your computer and use it in GitHub Desktop.
api = 'https://oauth.reddit.com'
res = requests.get(f'{api}/r/wallstreetbets/new', headers = headers, params = {'limit': '100'})
data = res.json()
#this would contain all the most recent 100 messages from the subreddit in a json format.]
#A json format is a very popular format that resembles a dictionary.
#feel free to check it our or trace the json document tree for what you want
#for this tutorial we would be using a Pandas Dataframe
frame = pd.DataFrame({
'name':[],
'created_utc': [],
'subreddit':[],
'title':[],
'selftext':[],
'upvote_ratio':[],
'ups':[],
'downs':[],
'score':[]
})
for post in data['data']['children']:
frame = frame.append({
'name':post['data']['name'],
'created_utc': post['data']['created_utc'],
'subreddit':post['data']['subreddit'],
'title':post['data']['title'],
'selftext':post['data']['selftext'],
'upvote_ratio':post['data']['upvote_ratio'],
'ups':post['data']['ups'],
'downs':post['data']['downs'],
'score':post['data']['score']
}, ignore_index = True)
frame
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment