Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import praw
- import sys
- import time
- comment_limit = None
- def info(*args, **kwargs):
- print(*args, file=sys.stderr, **kwargs)
- ################################################################################
- if len(sys.argv) < 3:
- raise Exception('Usage: %s USERNAME OUTPUT_FILE' % sys.argv[0])
- redditor_name = sys.argv[1]
- output_file = sys.argv[2]
- # set up API objects
- info('fetching comments by ' + redditor_name)
- r = praw.Reddit(user_agent='reddit-user-comments.py')
- user = r.get_redditor(redditor_name)
- comments = user.get_comments(limit=comment_limit)
- # fetch data from Reddit
- comment_bodies = []
- for comment in comments:
- comment_bodies.append(['___\n***#',
- ': [%s](%s)***\n\n%s\n___\n' % (time.strftime('%Y-%m-%d %H:%M:%S UTC',
- time.gmtime(comment.created_utc)),
- comment.permalink,
- comment.body.strip())])
- info('\rdownloaded %d comments' % len(comment_bodies), end='')
- info('')
- # write output file
- info('writing ' + output_file)
- with open(output_file, 'w') as out:
- for n, body in enumerate(reversed(comment_bodies)):
- print(body[0] + str(n+1) + body[1], file=out)
- info('done!')
Add Comment
Please, Sign In to add comment