Skip to content

Instantly share code, notes, and snippets.

@Celeo
Last active December 25, 2015 17:28
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 Celeo/7012867 to your computer and use it in GitHub Desktop.
Save Celeo/7012867 to your computer and use it in GitHub Desktop.
Uses PRAW to fetch a user's comment and write to a file.
import praw
from datetime import datetime
utc_now = datetime.utcnow()
def main():
username = raw_input('Username: ')
password = raw_input('Password: ')
limit = raw_input('Fetch limit: ')
limit = int(limit)
r = praw.Reddit(user_agent='Comment fetcher for /u/' + username)
r.login(username, password)
user = r.get_redditor(username)
count = 0
f = open('Comment.txt', 'w')
for comment in user.get_comments(sort='new'):
f.write('Date: {0}\nLink: {1}\nScore: {2}\nPost: {3}'.format(format_date(comment.created_utc), comment.permalink, comment.score, comment.body))
f.write('\n-------------------------------\n')
count += 1
print 'Comment #' + str(count)
if count == limit:
break
f.close()
print 'Done'
def format_date(date):
return datetime.fromtimestamp(date).strftime('%m/%d/%Y @ %I:%M:%S %p')
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment