Last active
December 25, 2015 17:28
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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