Skip to content

Commit

Permalink
Detect UK trad grading and avoid trying to convert it
Browse files Browse the repository at this point in the history
  • Loading branch information
dannagr committed Nov 12, 2021
1 parent 48e68be commit 5965549
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions climbinggradebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
import os
import praw
import re
import time

reddit = praw.Reddit('climbingbot')

NAtoEU = {}
EUtoNA= {}

with open('gradeconversions.csv', 'rt') as csvfile:
grades = csv.reader(csvfile, delimiter=',')
for row in grades:
NAtoEU[row[0]] = row[1]
EUtoNA[row[1]] = row[0]

# source for lines 17-26: https://github.com/shantnu/RedditBot/blob/master/Part2/reply_post.py
# source for lines 18-27: https://github.com/shantnu/RedditBot/blob/master/Part2/reply_post.py
if not os.path.isfile("do_not_comment.txt"):
do_not_comment = []

Expand All @@ -32,13 +32,15 @@
yosemite_grades_regex="[5][.]\d\d?[abcdABCD]?[+-]?"
# ex: 10a/b
yosemite_shorthand_regex="1\d[abcdABCD](\/[abcdABCD])?[+-]?"

# try to avoid titles with UK grade system for now
uk="[uU][kK]"
uk2="[eE][0-9]"

def comment(grade, submission, convertedGrade):
if submission.id not in do_not_comment:
# only comment if converted grade is not already in the title
if not re.search(convertedGrade, submission.title) and not re.search(uk, submission.title):
print("commenting: **" + grade + "** converts to **" + convertedGrade + "**")
if not re.search(convertedGrade, submission.title) and not re.search(uk, submission.title) and not re.search(uk2, submission.title):
submission.reply("**" + grade + "** converts to **" + convertedGrade + "**")
do_not_comment.append(submission.id)

Expand All @@ -58,19 +60,20 @@ def find_grade_in_title(submission, regex, conversion, prefix=""):
search_for_proj_bot(submission)
comment(grade, submission, conversion[grade])

# Delete recent comment if it's at negative karma or if u/MountainProjectBot added a comment
def check_recent_comments():
for comment in reddit.redditor("GradeConversionBot").comments.new(limit=5):
post = comment.submission
if comment.score <= -1:
comment.delete()
print("deleted comment " + str(comment.id))

post.comments.replace_more(limit=0)
for top_level_comment in post.comments:
if top_level_comment.author == "MountainProjectBot":
comment.delete()

subreddit = reddit.subreddit("rockclimbing+slabistheworst+climbing+climbingporn")

for submission in subreddit.new(limit=10):
find_grade_in_title(submission, yosemite_shorthand_regex, NAtoEU, "5.")
find_grade_in_title(submission, yosemite_grades_regex, NAtoEU)
Expand Down

0 comments on commit 5965549

Please sign in to comment.