Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import re
- from collections import defaultdict
- def main():
- reddit = praw.Reddit(client_id= '',
- client_secret= '',
- password= '',
- username= '',
- user_agent= 'TowerOfTrial_bot')
- subreddit = reddit.subreddit('endlessfrontier')
- for submission in subreddit.stream.submissions():
- if "tower of trial" in submission.title.lower():
- if submission.author.name.lower() == 'darthreborn':
- solutions = solution_check(submission.comments)
- old_solutions = old_solution_check(submission.selftext)
- post = merge_solutions(solutions, old_solutions)
- submission.edit(post)
- def merge_solutions(solutions, old_solutions):
- body = '''Hello All! I will be hosting Server 1 ToT.
- Please post below and lets have a great ToT! I will update this post at least every 8 hours, maybe more often as i have time so long as new solutions are posted. I will stop updating the list after each entry has at least one solution. Thank you all for your support!
- New to the tower? Click here.
- Not sure about an abbreviation? Check here!
- Have ideas on how to make this more efficient / useful? Msg /u/DarthReborn
- Early bird? No Solutions yet? Check here for a list of premade solutions to known problems.
- Still don't see anything useful? Ask someone from the official discord in channel #s1_toweroftrial for help. You must assign yourself to server 1 in #role_commands to see the channel. Contact @RebornsNavy for assistance.
- Want to help streamline this process and can code? Msg /u/DarthReborn so we can collaborate on a useful solution!\n\n'''
- for k, v in solutions.items():
- try:
- old_line = old_solutions[k]
- if v not in old_line:
- string = '\n\n '.join(v)
- temp = str(k) + ":" + str(string) +'\n\n'
- body += temp
- except KeyError:
- print key + " is not valid"
- return body
- def old_solution_check(body):
- lst = []
- solution = re.split(':|\n\n', body)
- for n in range(0, len(solution), 2):
- if len(solution)%2 is 1:
- continue
- level = num(solution[n].strip())
- if level > 0:
- line = solution[n+1]
- lst.append((level,line))
- old_solutions = defaultdict(list)
- for k, v in lst:
- old_solutions[k].append(v)
- return old_solutions
- def solution_check(comments):
- lst = []
- for comment in comments:
- solution = re.split(':|\n', comment.body)
- solution = filter(lambda s: s.strip(), solution)
- if len(solution)%2 is 1:
- continue
- for n in range(0, len(solution), 2):
- level = num(solution[n].strip())
- if level > 0:
- line = solution[n+1]
- lst.append((level,line))
- solutions = defaultdict(list)
- for k, v in lst:
- solutions[k].append(v)
- return solutions
- def num(s):
- try:
- return int(s)
- except ValueError:
- return -1
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement