Skip to content

Instantly share code, notes, and snippets.

@yi-jiayu
Created April 25, 2018 04:02
Show Gist options
  • Save yi-jiayu/b2e9f6ee45318dd2d9cc5aa5cfdeeed0 to your computer and use it in GitHub Desktop.
Save yi-jiayu/b2e9f6ee45318dd2d9cc5aa5cfdeeed0 to your computer and use it in GitHub Desktop.
import praw
CLIENT_ID = 'YOUR_CLIENT_ID'
CLIENT_SECRET = 'YOUR_CLIENT_SECRET'
REDDIT_USERNAME = 'your reddit username'
# https://www.reddit.com/r/singapore/comments/8eoesx/rsingapore_random_discussion_and_small_questions/
submission_id = '8eoesx'
reddit = praw.Reddit(client_id=CLIENT_ID, client_secret=CLIENT_SECRET,
user_agent='Markov Text Generation from Reddit Comments by /u/' + REDDIT_USERNAME)
submission = reddit.submission(id=submission_id)
submission.comments.replace_more(limit=None)
# here is our comment iterator
for comment in submission.comments.list():
# Python 3.6 f-string syntax (https://www.python.org/dev/peps/pep-0498/)
print(f'{comment.author}: {comment.body}')
# pre-Python 3.6
# print('{}: {}'.format(comment.author, comment.body))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment