Last active
September 29, 2022 13:50
-
-
Save Heliodex/39019aaa1a42bb162524c6027e518e19 to your computer and use it in GitHub Desktop.
PRAW Reddit bot to correct wrong counting comments from r/oneupmanship
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
# Heliodex 2022/05/13 | |
# Last edited 2022/09/29 -- Update the latest comment thread automatically every 100 upmanships | |
# In response to repeated requests to create a bot that corrects peoples' upmanships | |
import praw | |
import praw.models.reddit.comment | |
completedComments = open("ids.txt", "r+") | |
lines = completedComments.read().split() | |
specialChars = ["#", "`", "*", "_", "~", "^", | |
"(", ")", "/", "\\", "!", "<", ">", "[", "]", ":", "-", ".", "|", "\n"] | |
reddit = praw.Reddit(username="UpmanshipCorrector", password="hunter2", | |
client_id="*", client_secret="*", user_agent="*") | |
newestUpmanship = reddit.submission("qpnytd") | |
sub = reddit.subreddit("oneupmanship") | |
while True: | |
try: | |
for comment in sub.stream.comments(): | |
if comment.submission == reddit.submission("sab2o6") and comment.id not in lines: | |
completedComments.write("\n" + comment.id) | |
lines.append(comment.id) | |
parent = comment.parent() | |
gparent = parent.parent() | |
if type(parent) != praw.models.reddit.comment.Comment or type(gparent) != praw.models.reddit.comment.Comment: | |
continue | |
cleanedComment = comment.body.split()[0] | |
cleanedAncestor = parent.body.split()[0] | |
cleanedAncestor2 = gparent.body.split()[0] | |
for i in specialChars: | |
cleanedComment = cleanedComment.replace(i, "") | |
cleanedAncestor = cleanedAncestor.replace(i, "") | |
cleanedAncestor2 = cleanedAncestor2.replace(i, "") | |
print(f"{cleanedComment}, {cleanedAncestor}, {cleanedAncestor2}") | |
if cleanedComment.isdigit() and cleanedAncestor.isdigit() and cleanedAncestor2.isdigit() and int(cleanedComment) - 1 != int(cleanedAncestor) and int(cleanedAncestor) - 1 == int(cleanedAncestor2): | |
print("Correcting...") | |
comment.reply(body=( | |
f"Check your upmanship ({cleanedComment}). Should it be {str(int(cleanedAncestor) + 1)} upmanship?")) | |
elif cleanedComment.endswith("00"): | |
print("Updating...") | |
newestUpmanship.reply(body=( | |
f"{cleanedComment}\n[https://www.reddit.com/r/oneupmanship/comments/sab2o6/original_oneupmanship_post_was_archived_today/{comment.id}/](https://www.reddit.com/r/oneupmanship/comments/sab2o6/original_oneupmanship_post_was_archived_today/{comment.id}/)")) | |
except Exception as e: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment