Skip to content

Instantly share code, notes, and snippets.

@citostyle
Created October 9, 2018 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save citostyle/283b785dc85cc0e0f092eb095b9ad6c1 to your computer and use it in GitHub Desktop.
Save citostyle/283b785dc85cc0e0f092eb095b9ad6c1 to your computer and use it in GitHub Desktop.
Retrieve Reddit posts from a particular subreddit using the `praw` Python library
def extract_submissions(client_id, client_secret, user_agent, subreddit_name):
reddit = praw.Reddit(client_id=client_id, client_secret=client_secret, user_agent=user_agent)
subreddit = reddit.subreddit(subreddit_name)
submissions = [{'id': s.id, 'title': s.title, 'upvotes': s.ups, 'downvotes': s.downs, 'href': s.permalink, 'number_of_comments': s.num_comments, 'content': s.selftext}
for s in subreddit.hot(limit=None)]
return submissions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment