Last active
March 23, 2022 03:21
-
-
Save danieltharp/4f4f9be253d4c4c0eafeb00ad1fdae11 to your computer and use it in GitHub Desktop.
Source for the script to remind people of their new years resolution
This file contains hidden or 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 | |
reddit = praw.Reddit(client_id='', | |
client_secret='', | |
password='', | |
user_agent='', | |
username='') | |
readingfrom = reddit.submission('3ywu0b') # Last year's thread. | |
body = [] | |
author = [] | |
readingfrom.comments.replace_more(None) | |
postingto = reddit.submission('5l9x4k') # Today's follow-up thread. | |
for comment in readingfrom.comments: | |
if comment.body == '[deleted]': # There could be more conditionals for common comment-overwriting scripts | |
continue | |
elif comment.author is None: | |
continue | |
body.append(comment.body) | |
author.append(comment.author.name) | |
commentcount = str(len(body)) | |
print 'I found ' + commentcount + ' comments to reply to.' | |
for x in range(0, len(body)): # if the bot barfs, it'll print the last comment completed to the console, replace 0 with the next one to process | |
body[x] = body[x].replace('\n', '\n> ') # Quote the user correctly with each line-break. | |
try: | |
postingto.reply('/u/' + author[x] + '\n\nExactly one year ago, I asked what you wanted to achieve by 31st Dec 2016 and I said I would message you to see if you achieved it. Well, today is the day!\n\nYour goal was:\n\n> ' + body[x]) | |
except (TypeError, UnicodeEncodeError): # I'm not actually sure this is needed or was a relic of testing. | |
postingto.reply('/u/' + author[x] + '\n\nExactly one year ago, I asked what you wanted to achieve by 31st Dec 2016 and I said I would message you to see if you achieved it. Well, today is the day!\n\nYour goal was:\n\n> ' + body[x].encode('utf8')) | |
print str(x) + '/' + commentcount |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment