From 7a4f9e7c4d9d3e382440e7c5d77f0dd5aff61af3 Mon Sep 17 00:00:00 2001 From: PokestarFan Date: Sat, 16 Sep 2017 19:39:19 -0400 Subject: [PATCH 01/14] Major changes --- .gitignore | 7 +-- delete.py | 26 +++++----- deleteallcomments.py | 19 +++++++ duplicate.py | 111 ++++++++++++++++++++--------------------- goodbadbot.py | 27 ---------- lowpostremover.py | 51 ++++++++----------- modules/logger.py | 19 +++++++ run.bat | 3 ++ updateblockedusers.bat | 4 ++ 9 files changed, 135 insertions(+), 132 deletions(-) create mode 100644 deleteallcomments.py delete mode 100644 goodbadbot.py create mode 100644 modules/logger.py create mode 100644 run.bat create mode 100644 updateblockedusers.bat diff --git a/.gitignore b/.gitignore index 023fe5e..cf130e3 100644 --- a/.gitignore +++ b/.gitignore @@ -101,17 +101,14 @@ ENV/ .mypy_cache/ #my login -login.py -Utlities/login.py +*login.py #pycharm .idea/ #files used by program blockusers.txt -posts_written_to.txt -writes.txt -replies.txt #logs *.log +logs/ diff --git a/delete.py b/delete.py index e1c53eb..d76bb56 100644 --- a/delete.py +++ b/delete.py @@ -1,15 +1,17 @@ import praw -from login import reddit +from modules.logger import setup_logger +from modules.login import reddit +import logging +logger = setup_logger('user_removed_comments') -def main(limit, count=0): - for comment in r.redditor(str(user)).comments.new(limit=limit): - comment.delete() - count = count + 1 - print('Finished comment #'+str(count)) - -if __name__ == '__main__': - limit = input('How many recent comments to delete? Type None for all comments') - count = 0 - main(limit, count) - print('Complete') \ No newline at end of file +for item in reddit.inbox.stream(): + logger.debug('On item {}'.format(str(item))) + try: + if item.body.lower() == 'delete': + item.parent.delete() + logging.info('Comment {} removed'.format(str(item.parent))) + item.reply('The top level post has been removed.') + except: + logging.debug('Item {} skipped'.format(str(item))) + pass \ No newline at end of file diff --git a/deleteallcomments.py b/deleteallcomments.py new file mode 100644 index 0000000..ed59b53 --- /dev/null +++ b/deleteallcomments.py @@ -0,0 +1,19 @@ +import praw +from modules.logger import setup_logger +from modules.login import reddit +import logging + +logger = setup_logger('remallcomments') + + +def main(count=0): + for comment in r.redditor(str(r.user.me())).comments.new(limit=None): + comment.delete() + logging.info('Finished comment #'+str(count)+', id {}'.format(str(comment))) + +if __name__ == '__main__': + while True: + try: + main() + except: + logging.error('Error!', exc_info=True) \ No newline at end of file diff --git a/duplicate.py b/duplicate.py index dc5cd62..fb0da70 100644 --- a/duplicate.py +++ b/duplicate.py @@ -1,70 +1,67 @@ -from datetime import datetime +from modules.logger import setup_logger import logging +from datetime import datetime import praw import prawcore -import sys -from login import reddit - - -file_handler = logging.FileHandler(filename='duplicates_{}.log'.format(datetime.now().strftime('%m_%d_%y'))) -stdout_handler = logging.StreamHandler(sys.stdout) -handlers = [file_handler, stdout_handler] - -logging.basicConfig( - level=logging.INFO, - format='[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s', - handlers=handlers -) +from modules.login import reddit -logger = logging.getLogger(__name__) +logger = setup_logger('duplicates') def action(): for sub_id in reddit.subreddit('all').stream.submissions(): - logging.debug('Starting submission {}'.format(sub_id)) - blockeduser = 0 - duplicates = [] - submission = praw.models.Submission(reddit, id = sub_id) - with open('blockusers.txt','r') as newfile: - for line in newfile.readlines(): - line = line.strip('\n') - if str(submission.author) == line or 'bot' in str(submission.author).lower(): - blockeduser = 1 - logger.debug('User {}\'s submission {} was blocked from posting'.format(str(submission.author),str(sub_id))) - else: - pass - if blockeduser == 0: - for duplicate in submission.duplicates(): - dup_sub = praw.models.Submission(reddit, id = duplicate) - if 'imagesof' not in str(dup_sub.subreddit).lower() and 'auto' not in str(dup_sub.subreddit).lower() and 'bot' not in str(dup_sub.author).lower(): - time = dup_sub.created - time = str(datetime.fromtimestamp(time)) - author = str(dup_sub.author) - if str(submission.author) == author: - author = author + '[author of both threads]' - duplicates.append({'title':str(dup_sub.title), 'subreddit':str(dup_sub.subreddit), 'link':'https://www.reddit.com'+str(dup_sub.permalink), 'time':str(time), 'author':author, 'karma': str(dup_sub.score)}) - if len(duplicates) > 0: - message = 'Here is a list of threads in other subreddits about the same content:\n' - for dup in duplicates: - message = str(message + '\n * [{}]({}) on /r/{} with {} karma (created at {} by {})').format(dup['title'], dup['link'], dup['subreddit'], dup['karma'],dup['time'], dup['author']) - message = message + '\n\n ---- \n\n ^^I ^^am ^^a ^^bot ^^[FAQ](https://www.reddit.com/r/DuplicatesBot/wiki/index)-[Code](https://github.com/PokestarFan/DuplicateBot)-[Bugs](https://www.reddit.com/r/DuplicatesBot/comments/6ypgmx/bugs_and_problems/)-[Suggestions](https://www.reddit.com/r/DuplicatesBot/comments/6ypg85/suggestion_for_duplicatesbot/)-[Block](https://www.reddit.com/r/DuplicatesBot/wiki/index#wiki_block_bot_from_tagging_on_your_posts)' - try: - submission.reply(message) - logger.info('Message posted on {}'.format(sub_id)) - logger.debug('Message: {}'.format(message)) - message = '' - except(praw.exceptions.APIException, UnboundLocalError)as e: - logger.info('Submission {} has been skipped due to missing text'.format(sub_id)) + try: + logging.debug('Starting submission {}'.format(sub_id)) + blockeduser = 0 + duplicates = [] + submission = praw.models.Submission(reddit, id = sub_id) + with open('blockusers.txt','r') as newfile: + for line in newfile.readlines(): + line = line.strip('\n') + if str(submission.author) == line or 'bot' in str(submission.author).lower(): + blockeduser = 1 + logger.debug('User {}\'s submission {} was blocked from posting'.format(str(submission.author),str(sub_id))) + else: + pass + if blockeduser == 0: + for duplicate in submission.duplicates(): + dup_sub = praw.models.Submission(reddit, id = duplicate) + if 'imagesof' not in str(dup_sub.subreddit).lower() and 'auto' not in str(dup_sub.subreddit).lower() and 'bot' not in str(dup_sub.author).lower() and 'mistyfront' not in str(dup_sub.subreddit).lower() and 'unitedfederation' not in str(dup_sub.subreddit).lower(): + time = dup_sub.created + time = str(datetime.fromtimestamp(time)) + author = str(dup_sub.author) + if str(submission.author) == author: + author = author + '[author of both threads]' + duplicates.append({'title':str(dup_sub.title), 'subreddit':str(dup_sub.subreddit), 'link':'https://www.reddit.com'+str(dup_sub.permalink), 'time':str(time), 'author':author, 'karma': str(dup_sub.score)}) + if len(duplicates) > 0: + message = 'Here is a list of threads in other subreddits about the same content:\n' + for dup in duplicates: + message = str(message + '\n * [{}]({}) on /r/{} with {} karma (created at {} by {})').format(dup['title'], dup['link'], dup['subreddit'], dup['karma'],dup['time'], dup['author']) + message = message + '\n\n ---- \n\n ^^I ^^am ^^a ^^bot ^^[FAQ](https://www.reddit.com/r/DuplicatesBot/wiki/index)-[Code](https://github.com/PokestarFan/DuplicateBot)-[Bugs](https://www.reddit.com/r/DuplicatesBot/comments/6ypgmx/bugs_and_problems/)-[Suggestions](https://www.reddit.com/r/DuplicatesBot/comments/6ypg85/suggestion_for_duplicatesbot/)-[Block](https://www.reddit.com/r/DuplicatesBot/wiki/index#wiki_block_bot_from_tagging_on_your_posts)' try: + submission.reply(message) + logger.info('Message posted on {}'.format(sub_id)) logger.debug('Message: {}'.format(message)) + message = '' + except(praw.exceptions.APIException, UnboundLocalError)as e: + logger.debug('Submission {} has been skipped due to missing text'.format(sub_id)) + message = '' + except(prawcore.exceptions.Forbidden): + logger.debug('You are blocked on /r/{}'.format(str(submission.subreddit))) + message = '' + except(AssertionError): + logger.debug('Assertion Error occured! Printing message and traceback.') + logger.debug(message + str(len(message)), exc_info=True) + message = '' + except(KeyboardInterrupt): + raise KeyboardInterrupt except: - logger.debug('Message output for exception ') - message = '' - except(prawcore.exceptions.Forbidden): - logger.info('You are blocked on /r/{}'.format(str(submission.subreddit))) - message = '' - except: - logger.error('Error occured!', exc_info=True) - message = '' + logger.error('Error occured!', exc_info=True) + message = '' + except(KeyboardInterrupt): + raise KeyboardInterrupt + except: + logger.error('Error on submission {} occured.'.format(str(sub_id)), exc_info=True) + if __name__ == '__main__': diff --git a/goodbadbot.py b/goodbadbot.py deleted file mode 100644 index 6241bd8..0000000 --- a/goodbadbot.py +++ /dev/null @@ -1,27 +0,0 @@ -import time -import praw -from login import reddit - - -def main(): - while True: - for item in reddit.inbox.all(limit=5): - with open('replies.txt', 'r') as readfile: - for line in readfile.readlines(): - if line == item: - pass - else: - try: - if 'good' and 'bot' in item.body: - item.reply('Good human') - with open('replies.txt', 'a') as file: - file.write(str(item)+'\n') - elif 'bad' and 'bot' in item.body: - item.reply('bad human') - with open('replies.txt', 'a') as file: - file.write(str(item)+'\n') - except: - pass - -if __name__ == '__main__': - main() \ No newline at end of file diff --git a/lowpostremover.py b/lowpostremover.py index 85a2c9b..58561d5 100644 --- a/lowpostremover.py +++ b/lowpostremover.py @@ -9,7 +9,11 @@ import time import praw -from login import reddit as r +from modules.logger import setup_logger +from modules.login import reddit as r +import logging + +logger = setup_logger('low_score_remover') ########################### # definitions @@ -23,7 +27,6 @@ #defining the searching and removal def action(): - global submission_titles #making global submission title list global comment_submissions #making glocal comment submission title list comment_submissions = [] submission_titles = [] @@ -31,43 +34,30 @@ def action(): comment_number = 0 current_submission_number = 0 current_comment_number = 0 - print('Searching...') + logging.info('Searching...') user = r.user.me() - for submission in r.redditor(str(user)).submissions.new(limit=None): #scanning all submissions by reddit user without limit - if submission.score < setvalue: #if statement checking the submission score < 0 - submission.delete() #deleting the submission - submission_titles.append(submission.title) #adding the submission title to the list for comment in r.redditor(str(user)).comments.new(limit=None): #scanning all comments by reddit user without limit + logging.debug('On comment {}'.format(str(comment))) if comment.score < setvalue: #if statement checking the comment score < 0 comment.delete() #deleteing the comment if < 0 + logging.info('Removed comment {}'.format(str(comment))) comment_submissions.append(comment.submission.title) #adding the comment's original submission title to the list #defining the outputs def print_results(): - print('Search Complete') - print('--------------------------------------------------') - #if statement. True if there is 1 or more submissions removed. - if len(submission_titles) > 0: - #printing true results - print('Removed ' + str(len(submission_titles)) + ' submission(s).') - print('Submission title(s) include: ') - print(*submission_titles, sep='\n') #printing submission titles with line breaks - print('--------------------------------------------------') - else: - #printing false results - print('No submissions removed.') - print('--------------------------------------------------') + logging.info('Search Complete') + logging.info('--------------------------------------------------') #if statement. True if there is 1 or more comments removed. if len(comment_submissions) > 0: - #printing true results - print('Removed ' + str(len(comment_submissions)) + ' comment(s).') - print('Comments were under the following submissions: ') - print(*comment_submissions, sep='\n') #printing comment's submission's titles with line breaks - print('--------------------------------------------------') + #logging.infoing true results + logging.info('Removed ' + str(len(comment_submissions)) + ' comment(s).') + logging.info('Comments were under the following submissions: ') + logging.info(*comment_submissions, sep='\n') #logging.infoing comment's submission's titles with line breaks + logging.info('--------------------------------------------------') else: - #printing false results - print('No comments removed.') - print('--------------------------------------------------') + #logging.infoing false results + logging.info('No comments removed.') + logging.info('--------------------------------------------------') ########################### # code execution @@ -77,7 +67,6 @@ def print_results(): def main(): action() print_results() - + while True: - main() - time.sleep(600) \ No newline at end of file + main() \ No newline at end of file diff --git a/modules/logger.py b/modules/logger.py new file mode 100644 index 0000000..2e89e2e --- /dev/null +++ b/modules/logger.py @@ -0,0 +1,19 @@ +import logging +from datetime import datetime +import sys + + +def setup_logger(name): + file_handler = logging.FileHandler(filename='logs/{}_{}.log'.format(name, datetime.now().strftime('%m_%d_%y'))) + stdout_handler = logging.StreamHandler(sys.stdout) + handlers = [file_handler, stdout_handler] + + logging.basicConfig( + level=logging.INFO, + format='[%(asctime)s] {%(filename)s:%(lineno)d} (%(funcName)s) %(levelname)s - %(message)s', + handlers=handlers + ) + + logger = logging.getLogger(__name__) + return logger + diff --git a/run.bat b/run.bat new file mode 100644 index 0000000..57e4ded --- /dev/null +++ b/run.bat @@ -0,0 +1,3 @@ +@echo off +py duplicate.py +run.bat \ No newline at end of file diff --git a/updateblockedusers.bat b/updateblockedusers.bat new file mode 100644 index 0000000..50a1554 --- /dev/null +++ b/updateblockedusers.bat @@ -0,0 +1,4 @@ +@echo off +SET /P somevar= Username: +echo %somevar%>>blockusers.txt +updateblockedusers.bat From 584437723e606db1822121526fcd4db2a5fe8001 Mon Sep 17 00:00:00 2001 From: PokestarFan Date: Sat, 16 Sep 2017 19:44:39 -0400 Subject: [PATCH 02/14] removed un-needed stuff --- lowpostremover.py | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/lowpostremover.py b/lowpostremover.py index 58561d5..89effe5 100644 --- a/lowpostremover.py +++ b/lowpostremover.py @@ -27,13 +27,6 @@ #defining the searching and removal def action(): - global comment_submissions #making glocal comment submission title list - comment_submissions = [] - submission_titles = [] - submission_number = 0 - comment_number = 0 - current_submission_number = 0 - current_comment_number = 0 logging.info('Searching...') user = r.user.me() for comment in r.redditor(str(user)).comments.new(limit=None): #scanning all comments by reddit user without limit @@ -41,32 +34,5 @@ def action(): if comment.score < setvalue: #if statement checking the comment score < 0 comment.delete() #deleteing the comment if < 0 logging.info('Removed comment {}'.format(str(comment))) - comment_submissions.append(comment.submission.title) #adding the comment's original submission title to the list - -#defining the outputs -def print_results(): - logging.info('Search Complete') - logging.info('--------------------------------------------------') - #if statement. True if there is 1 or more comments removed. - if len(comment_submissions) > 0: - #logging.infoing true results - logging.info('Removed ' + str(len(comment_submissions)) + ' comment(s).') - logging.info('Comments were under the following submissions: ') - logging.info(*comment_submissions, sep='\n') #logging.infoing comment's submission's titles with line breaks - logging.info('--------------------------------------------------') - else: - #logging.infoing false results - logging.info('No comments removed.') - logging.info('--------------------------------------------------') - -########################### -# code execution -########################### - - -def main(): - action() - print_results() -while True: - main() \ No newline at end of file +action() \ No newline at end of file From 9311fafcdc0819f02a05ad2f27c5ae5e8fc22f13 Mon Sep 17 00:00:00 2001 From: PokestarFan Date: Sat, 16 Sep 2017 20:26:10 -0400 Subject: [PATCH 03/14] More changes --- delete.py | 27 +++++++++++++++++++-------- duplicate.py | 2 +- run.bat | 5 +++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/delete.py b/delete.py index d76bb56..faa62af 100644 --- a/delete.py +++ b/delete.py @@ -2,16 +2,27 @@ from modules.logger import setup_logger from modules.login import reddit import logging +import time logger = setup_logger('user_removed_comments') -for item in reddit.inbox.stream(): - logger.debug('On item {}'.format(str(item))) + +def main(): try: - if item.body.lower() == 'delete': - item.parent.delete() - logging.info('Comment {} removed'.format(str(item.parent))) - item.reply('The top level post has been removed.') + for item in reddit.inbox.comment_replies(limit=30): + logger.debug('On item {}'.format(str(item))) + print(item.body) + try: + if 'delete' in item.body.lower(): + item.parent.delete() + logging.info('Comment {} removed'.format(str(item.parent))) + item.reply('The top level post has been removed.') + except: + logging.debug('Item {} skipped'.format(str(item))) except: - logging.debug('Item {} skipped'.format(str(item))) - pass \ No newline at end of file + logging.debug('Error!', exc_info=True) + main() + +while True: + main() + time.sleep(30) \ No newline at end of file diff --git a/duplicate.py b/duplicate.py index fb0da70..3e759f0 100644 --- a/duplicate.py +++ b/duplicate.py @@ -36,7 +36,7 @@ def action(): message = 'Here is a list of threads in other subreddits about the same content:\n' for dup in duplicates: message = str(message + '\n * [{}]({}) on /r/{} with {} karma (created at {} by {})').format(dup['title'], dup['link'], dup['subreddit'], dup['karma'],dup['time'], dup['author']) - message = message + '\n\n ---- \n\n ^^I ^^am ^^a ^^bot ^^[FAQ](https://www.reddit.com/r/DuplicatesBot/wiki/index)-[Code](https://github.com/PokestarFan/DuplicateBot)-[Bugs](https://www.reddit.com/r/DuplicatesBot/comments/6ypgmx/bugs_and_problems/)-[Suggestions](https://www.reddit.com/r/DuplicatesBot/comments/6ypg85/suggestion_for_duplicatesbot/)-[Block](https://www.reddit.com/r/DuplicatesBot/wiki/index#wiki_block_bot_from_tagging_on_your_posts)' + message = message + '\n\n ---- \n\n ^^I ^^am ^^a ^^bot ^^[FAQ](https://www.reddit.com/r/DuplicatesBot/wiki/index)-[Code](https://github.com/PokestarFan/DuplicateBot)-[Bugs](https://www.reddit.com/r/DuplicatesBot/comments/6ypgmx/bugs_and_problems/)-[Suggestions](https://www.reddit.com/r/DuplicatesBot/comments/6ypg85/suggestion_for_duplicatesbot/)-[Block](https://www.reddit.com/r/DuplicatesBot/wiki/index#wiki_block_bot_from_tagging_on_your_posts)\n\n^^Now ^^you ^^can ^^remove ^^the ^^comment ^^by ^^replying ^^delete!' try: submission.reply(message) logger.info('Message posted on {}'.format(sub_id)) diff --git a/run.bat b/run.bat index 57e4ded..48f8e9e 100644 --- a/run.bat +++ b/run.bat @@ -1,3 +1,4 @@ @echo off -py duplicate.py -run.bat \ No newline at end of file +start py duplicate.py +start py delete.py +start py lowpostremover.py \ No newline at end of file From 8a2ebc0c05b193b722fcb8348606e9793f8c6665 Mon Sep 17 00:00:00 2001 From: PokestarFan Date: Sun, 17 Sep 2017 09:43:28 -0400 Subject: [PATCH 04/14] More changes --- delete.py | 7 +++---- duplicate.py | 4 ++-- lowpostremover.py | 8 +++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/delete.py b/delete.py index faa62af..bcfdf95 100644 --- a/delete.py +++ b/delete.py @@ -9,13 +9,12 @@ def main(): try: - for item in reddit.inbox.comment_replies(limit=30): + for item in reddit.inbox.stream(): logger.debug('On item {}'.format(str(item))) - print(item.body) try: if 'delete' in item.body.lower(): - item.parent.delete() - logging.info('Comment {} removed'.format(str(item.parent))) + item.parent().delete() + logging.info('Comment {} removed'.format(str(item.parent()))) item.reply('The top level post has been removed.') except: logging.debug('Item {} skipped'.format(str(item))) diff --git a/duplicate.py b/duplicate.py index 3e759f0..f3805b0 100644 --- a/duplicate.py +++ b/duplicate.py @@ -28,9 +28,9 @@ def action(): if 'imagesof' not in str(dup_sub.subreddit).lower() and 'auto' not in str(dup_sub.subreddit).lower() and 'bot' not in str(dup_sub.author).lower() and 'mistyfront' not in str(dup_sub.subreddit).lower() and 'unitedfederation' not in str(dup_sub.subreddit).lower(): time = dup_sub.created time = str(datetime.fromtimestamp(time)) - author = str(dup_sub.author) + author = '/u/'+str(dup_sub.author) if str(submission.author) == author: - author = author + '[author of both threads]' + author = author + ' [author of both threads]' duplicates.append({'title':str(dup_sub.title), 'subreddit':str(dup_sub.subreddit), 'link':'https://www.reddit.com'+str(dup_sub.permalink), 'time':str(time), 'author':author, 'karma': str(dup_sub.score)}) if len(duplicates) > 0: message = 'Here is a list of threads in other subreddits about the same content:\n' diff --git a/lowpostremover.py b/lowpostremover.py index 89effe5..e0cb7fe 100644 --- a/lowpostremover.py +++ b/lowpostremover.py @@ -16,7 +16,7 @@ logger = setup_logger('low_score_remover') ########################### -# definitions +# defistarnitions ########################### #defining the log in process @@ -34,5 +34,7 @@ def action(): if comment.score < setvalue: #if statement checking the comment score < 0 comment.delete() #deleteing the comment if < 0 logging.info('Removed comment {}'.format(str(comment))) - -action() \ No newline at end of file + +while True: + action() + time.sleep(60) \ No newline at end of file From f660d65fe514c1758cc928207f440cff8822ae34 Mon Sep 17 00:00:00 2001 From: PokestarFan Date: Sun, 17 Sep 2017 12:20:17 -0400 Subject: [PATCH 05/14] More changes, new module --- .gitignore | 3 +++ delete.py | 7 ++++-- duplicate.py | 3 ++- gb-bb.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++ lowpostremover.py | 1 - modules/footer.py | 1 + 6 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 gb-bb.py create mode 100644 modules/footer.py diff --git a/.gitignore b/.gitignore index cf130e3..8a565b0 100644 --- a/.gitignore +++ b/.gitignore @@ -112,3 +112,6 @@ blockusers.txt #logs *.log logs/ + +#good bot bad bot file +comments_written_to.txt \ No newline at end of file diff --git a/delete.py b/delete.py index bcfdf95..f581746 100644 --- a/delete.py +++ b/delete.py @@ -1,6 +1,7 @@ import praw from modules.logger import setup_logger from modules.login import reddit +from modules.footer import footer import logging import time @@ -15,11 +16,13 @@ def main(): if 'delete' in item.body.lower(): item.parent().delete() logging.info('Comment {} removed'.format(str(item.parent()))) - item.reply('The top level post has been removed.') + item.reply('The top level post has been removed.'+footer) except: logging.debug('Item {} skipped'.format(str(item))) + except(KeyboardInterrupt): + raise KeyboardInterrupt except: - logging.debug('Error!', exc_info=True) + logging.error('Error!', exc_info=True) main() while True: diff --git a/duplicate.py b/duplicate.py index f3805b0..2752868 100644 --- a/duplicate.py +++ b/duplicate.py @@ -4,6 +4,7 @@ import praw import prawcore from modules.login import reddit +from modules.footer import footer logger = setup_logger('duplicates') @@ -36,7 +37,7 @@ def action(): message = 'Here is a list of threads in other subreddits about the same content:\n' for dup in duplicates: message = str(message + '\n * [{}]({}) on /r/{} with {} karma (created at {} by {})').format(dup['title'], dup['link'], dup['subreddit'], dup['karma'],dup['time'], dup['author']) - message = message + '\n\n ---- \n\n ^^I ^^am ^^a ^^bot ^^[FAQ](https://www.reddit.com/r/DuplicatesBot/wiki/index)-[Code](https://github.com/PokestarFan/DuplicateBot)-[Bugs](https://www.reddit.com/r/DuplicatesBot/comments/6ypgmx/bugs_and_problems/)-[Suggestions](https://www.reddit.com/r/DuplicatesBot/comments/6ypg85/suggestion_for_duplicatesbot/)-[Block](https://www.reddit.com/r/DuplicatesBot/wiki/index#wiki_block_bot_from_tagging_on_your_posts)\n\n^^Now ^^you ^^can ^^remove ^^the ^^comment ^^by ^^replying ^^delete!' + message = message + footer try: submission.reply(message) logger.info('Message posted on {}'.format(sub_id)) diff --git a/gb-bb.py b/gb-bb.py new file mode 100644 index 0000000..76b73ce --- /dev/null +++ b/gb-bb.py @@ -0,0 +1,55 @@ +import praw +from modules.logger import setup_logger +from modules.login import reddit +import logging +from modules.footer import footer + +logger = setup_logger('good_bot_bad_bot') + +def main(): + try: + for item in reddit.inbox.stream(): + written_to = 0 + text = '' + with open('comments_written_to.txt', 'r') as file: + for line in file.readlines(): + if line == str(item) and written_to == 0: + written_to = 1 + logging.info('Comment {} has been already replied to.'.format(str(item))) + if written_to == 0: + if 'good bot' in str(item.body.lower()): + text = 'Good human' + item.reply(text+footer) + logging.info('Message with the text {} replied to comment {}'.format(text, str(item))) + with open('comments_written_to.txt', 'a') as file: + file.write(str(item)+'\n') + elif 'bad bot' in str(item.body.lower()): + text = 'Bad human' + item.reply(text+footer) + logging.info('Message with the text {} replied to comment {}'.format(text, str(item))) + with open('comments_written_to.txt', 'a') as file: + file.write(str(item)+'\n') + elif 'average bot' in str(item.body.lower()): + text = 'Average human' + item.reply(text+footer) + logging.info('Message with the text {} replied to comment {}'.format(text, str(item))) + with open('comments_written_to.txt', 'a') as file: + file.write(str(item)+'\n') + elif 'bot' in str(item.body.lower()): + strings = str(item.body.lower()).split('bot') + text = '{} human'.format(strings[0]) + item.reply(text+footer) + logging.info('Message with the text {} replied to comment {}'.format(text, str(item))) + with open('comments_written_to.txt', 'a') as file: + file.write(str(item)+'\n') + except(KeyboardInterrupt): + raise KeyboardInterrupt + except: + logging.error('Error', exc_info = True) + +if __name__ == '__main__': + while True: + try: + main() + except(KeyboardInterrupt): + raise KeyboardInterrupt \ No newline at end of file diff --git a/lowpostremover.py b/lowpostremover.py index e0cb7fe..86011c5 100644 --- a/lowpostremover.py +++ b/lowpostremover.py @@ -27,7 +27,6 @@ #defining the searching and removal def action(): - logging.info('Searching...') user = r.user.me() for comment in r.redditor(str(user)).comments.new(limit=None): #scanning all comments by reddit user without limit logging.debug('On comment {}'.format(str(comment))) diff --git a/modules/footer.py b/modules/footer.py new file mode 100644 index 0000000..518cfb7 --- /dev/null +++ b/modules/footer.py @@ -0,0 +1 @@ +footer = '\n\n ---- \n\n ^^I ^^am ^^a ^^bot ^^[FAQ](https://www.reddit.com/r/DuplicatesBot/wiki/index)-[Code](https://github.com/PokestarFan/DuplicateBot)-[Bugs](https://www.reddit.com/r/DuplicatesBot/comments/6ypgmx/bugs_and_problems/)-[Suggestions](https://www.reddit.com/r/DuplicatesBot/comments/6ypg85/suggestion_for_duplicatesbot/)-[Block](https://www.reddit.com/r/DuplicatesBot/wiki/index#wiki_block_bot_from_tagging_on_your_posts)\n\n^^Now ^^you ^^can ^^remove ^^the ^^comment ^^by ^^replying ^^delete!' \ No newline at end of file From 2d54e0539d2558d33965d09c46b712f8b7792cea Mon Sep 17 00:00:00 2001 From: PokestarFan Date: Sun, 17 Sep 2017 12:26:19 -0400 Subject: [PATCH 06/14] Update README.md --- README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e285c8..40fddcb 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Bot for duplicates # How to use * Unzip -* Create login.py with the following code: +* Go into the modules folder and create login.py with the following code: ```python import praw @@ -17,3 +17,23 @@ reddit = praw.Reddit(username = 'yourusername', password = 'yourpassword', clien * Use + +# Extra scripts + +There are extra scripts that come with the bot. + +## Delete.py + +This script will delete any comment if a person comments delete. It is a mandatory run. + +## gb-bb.py + +This script controls the good bot/bad bot reply part. It is optional. + +## lowpostremover.py + +This script removes any comment below 1 karma. It is optional but recommended. + +## deleteallcomments.py + +If the bot has screwed up and made major mistakes, this script will delete all of the bot's comments. From bef9f53cae902db1d32fe2be78a8631918ff508e Mon Sep 17 00:00:00 2001 From: PokestarFan Date: Sun, 17 Sep 2017 12:29:44 -0400 Subject: [PATCH 07/14] Set theme jekyll-theme-cayman --- _config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_config.yml b/_config.yml index 3397c9a..c419263 100644 --- a/_config.yml +++ b/_config.yml @@ -1 +1 @@ -theme: jekyll-theme-architect \ No newline at end of file +theme: jekyll-theme-cayman \ No newline at end of file From 8e0fc63925966c14dc82b66282c8b9eec2ed454e Mon Sep 17 00:00:00 2001 From: PokestarFan Date: Sun, 17 Sep 2017 12:35:22 -0400 Subject: [PATCH 08/14] Show downloads --- _config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/_config.yml b/_config.yml index 3397c9a..a6f0c65 100644 --- a/_config.yml +++ b/_config.yml @@ -1 +1,2 @@ -theme: jekyll-theme-architect \ No newline at end of file +theme: jekyll-theme-architect +show_downloads: true \ No newline at end of file From a06c15cd42b7ba07bee539fa38fc4bf92c4854d5 Mon Sep 17 00:00:00 2001 From: PokestarFan Date: Tue, 19 Sep 2017 20:21:02 -0400 Subject: [PATCH 09/14] Add logger level customization --- modules/logger.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/logger.py b/modules/logger.py index 2e89e2e..102cd48 100644 --- a/modules/logger.py +++ b/modules/logger.py @@ -3,13 +3,13 @@ import sys -def setup_logger(name): +def setup_logger(name, loglevel=logging.INFO): file_handler = logging.FileHandler(filename='logs/{}_{}.log'.format(name, datetime.now().strftime('%m_%d_%y'))) stdout_handler = logging.StreamHandler(sys.stdout) handlers = [file_handler, stdout_handler] logging.basicConfig( - level=logging.INFO, + level=loglevel, format='[%(asctime)s] {%(filename)s:%(lineno)d} (%(funcName)s) %(levelname)s - %(message)s', handlers=handlers ) From 5f8124cbaaf3b613701f52676543234a6623e876 Mon Sep 17 00:00:00 2001 From: PokestarFan Date: Wed, 20 Sep 2017 21:33:52 -0400 Subject: [PATCH 10/14] Major code overhaul --- duplicate.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/duplicate.py b/duplicate.py index 2752868..a277303 100644 --- a/duplicate.py +++ b/duplicate.py @@ -8,8 +8,8 @@ logger = setup_logger('duplicates') -def action(): - for sub_id in reddit.subreddit('all').stream.submissions(): +def run_bot(sub_id): + if True: try: logging.debug('Starting submission {}'.format(sub_id)) blockeduser = 0 @@ -62,7 +62,11 @@ def action(): raise KeyboardInterrupt except: logger.error('Error on submission {} occured.'.format(str(sub_id)), exc_info=True) - + + +def action(): + for sub_id in reddit.subreddit('all').stream.submissions(): + run_bot(sub_id) if __name__ == '__main__': From c7ad3232ff13e088f6f3852c8676f1c6f8561011 Mon Sep 17 00:00:00 2001 From: PokestarFan Date: Thu, 18 Jan 2018 18:15:52 -0500 Subject: [PATCH 11/14] Add --- duplicate.py | 158 +++++++++++++++++++++++++++++----------------- entriesadder.py | 44 +++++++++++++ modules/footer.py | 1 - modules/table.py | 4 ++ 4 files changed, 148 insertions(+), 59 deletions(-) create mode 100644 entriesadder.py delete mode 100644 modules/footer.py create mode 100644 modules/table.py diff --git a/duplicate.py b/duplicate.py index a277303..0b9b047 100644 --- a/duplicate.py +++ b/duplicate.py @@ -1,79 +1,121 @@ -from modules.logger import setup_logger import logging from datetime import datetime + import praw import prawcore +from pokestarfansloggingsetup import setup_logger + from modules.login import reddit -from modules.footer import footer +from modules.table import starter logger = setup_logger('duplicates') + +# noinspection PyBroadException +def generate_and_reply(submission): + footer = '\n\n----\n\n ^^I ^^am ^^a ^^bot ^^[FAQ](https://www.reddit.com/r/DuplicatesBot/wiki/index)-[' \ + 'Code](https://github.com/PokestarFan/DuplicateBot)-[Bugs](' \ + 'https://www.reddit.com/r/DuplicatesBot/comments/6ypgmx/bugs_and_problems/)-[Suggestions](' \ + 'https://www.reddit.com/r/DuplicatesBot/comments/6ypg85/suggestion_for_duplicatesbot/)-[Block ' \ + 'user (op only)' \ + '](' \ + 'https://www.reddit.com/message/compose/?to=DuplicatesBotBlocker&subject=remove%20user&message' \ + '={user})-[Block from subreddit (mods only)](' \ + 'https://www.reddit.com/message/compose/?to=DuplicatesBotBlocker&subject=remove%20subreddit' \ + '&message={sub})\n' \ + '\n^^Now ^^you ^^can ^^remove ^^the ^^comment ^^by ^^replying ^^delete! '.format(user= + str( + submission.author), sub=str(submission.subreddit)) + global message + sub_id = submission.subreddit + for dup_sub in submission.duplicates(): + duplicates = [] + time = dup_sub.created + time = str(datetime.fromtimestamp(time)) + author = '/u/' + str(dup_sub.author) + if str(submission.author) == author: + author = author + ' [author of both threads]' + duplicates.append(['[{}]({})'.format(str(dup_sub.title), 'https://www.reddit.com' + str(dup_sub.permalink)), + str(dup_sub.subreddit), author, str(time), str(dup_sub.score)]) + if len(duplicates) > 0: + message = 'Here is a list of threads in other subreddits about the same content:\n' + for dup in duplicates: + starter.add_row_with_list(dup) + message += '\n' + starter.table + message += '\n' + footer + try: + submission.reply(message) + logger.info('Message posted on {}'.format(sub_id)) + logger.debug('Message: {}'.format(message)) + message = '' + except praw.exceptions.APIException: + logger.debug('Submission {} has been skipped due to missing text.'.format(sub_id)) + message = '' + except prawcore.exceptions.Forbidden: + logger.debug('You are blocked on /r/{}'.format(str(submission.subreddit))) + message = '' + except AssertionError: + logger.debug('Assertion Error occured! Printing message and traceback.') + logger.debug(message + str(len(message)), exc_info=True) + message = '' + except(KeyboardInterrupt, SystemExit): + raise + except Exception: + logger.error('Error occurred!', exc_info=True) + message = '' + except: + logger.critical( + 'Massive Error occurred! Not part of the Exception, KeyboardInterrupt or SystemExit exceptions. Fix ASAP.', + exc_info=True) + message = '' + + def run_bot(sub_id): + global blocked_sub if True: try: - logging.debug('Starting submission {}'.format(sub_id)) - blockeduser = 0 - duplicates = [] - submission = praw.models.Submission(reddit, id = sub_id) - with open('blockusers.txt','r') as newfile: - for line in newfile.readlines(): - line = line.strip('\n') - if str(submission.author) == line or 'bot' in str(submission.author).lower(): - blockeduser = 1 - logger.debug('User {}\'s submission {} was blocked from posting'.format(str(submission.author),str(sub_id))) - else: - pass - if blockeduser == 0: - for duplicate in submission.duplicates(): - dup_sub = praw.models.Submission(reddit, id = duplicate) - if 'imagesof' not in str(dup_sub.subreddit).lower() and 'auto' not in str(dup_sub.subreddit).lower() and 'bot' not in str(dup_sub.author).lower() and 'mistyfront' not in str(dup_sub.subreddit).lower() and 'unitedfederation' not in str(dup_sub.subreddit).lower(): - time = dup_sub.created - time = str(datetime.fromtimestamp(time)) - author = '/u/'+str(dup_sub.author) - if str(submission.author) == author: - author = author + ' [author of both threads]' - duplicates.append({'title':str(dup_sub.title), 'subreddit':str(dup_sub.subreddit), 'link':'https://www.reddit.com'+str(dup_sub.permalink), 'time':str(time), 'author':author, 'karma': str(dup_sub.score)}) - if len(duplicates) > 0: - message = 'Here is a list of threads in other subreddits about the same content:\n' - for dup in duplicates: - message = str(message + '\n * [{}]({}) on /r/{} with {} karma (created at {} by {})').format(dup['title'], dup['link'], dup['subreddit'], dup['karma'],dup['time'], dup['author']) - message = message + footer - try: - submission.reply(message) - logger.info('Message posted on {}'.format(sub_id)) - logger.debug('Message: {}'.format(message)) - message = '' - except(praw.exceptions.APIException, UnboundLocalError)as e: - logger.debug('Submission {} has been skipped due to missing text'.format(sub_id)) - message = '' - except(prawcore.exceptions.Forbidden): - logger.debug('You are blocked on /r/{}'.format(str(submission.subreddit))) - message = '' - except(AssertionError): - logger.debug('Assertion Error occured! Printing message and traceback.') - logger.debug(message + str(len(message)), exc_info=True) - message = '' - except(KeyboardInterrupt): - raise KeyboardInterrupt - except: - logger.error('Error occured!', exc_info=True) - message = '' - except(KeyboardInterrupt): - raise KeyboardInterrupt - except: - logger.error('Error on submission {} occured.'.format(str(sub_id)), exc_info=True) + logging.debug('Starting submission {}'.format(str(sub_id))) + blocked_user = 0 + blocked_sub = 0 + submission = sub_id + try: + with open('blockusers.txt', 'r') as new_file: + for line in new_file.readlines(): + line = line.strip('\n') + if str(submission.author).lower() == line.lower() or 'bot' in str(submission.author).lower(): + blocked_user = 1 + break + except FileNotFoundError: + with open('blockusers.txt', 'w'): + blocked_user = 0 + try: + with open('blockedsubs.txt', 'r') as new_file: + for line in new_file.readlines(): + line = line.strip('\n') + if str(submission.subreddit).lower() == line.lower(): + blocked_sub = 1 + break + except FileNotFoundError: + with open('blockedsubs.txt', 'w'): + blocked_sub = 0 + if blocked_user == 0 and blocked_sub == 0: + generate_and_reply(sub_id) + except(KeyboardInterrupt, SystemExit): + raise + except Exception: + logger.error('Error on submission {} occurred.'.format(str(sub_id)), exc_info=True) def action(): for sub_id in reddit.subreddit('all').stream.submissions(): run_bot(sub_id) - + if __name__ == '__main__': while True: try: action() - except(KeyboardInterrupt): - raise KeyboardInterrupt - except: - logger.critical('Error has occured when running main loop, please resolve asap', exc_info=True) \ No newline at end of file + except(KeyboardInterrupt, SystemExit): + raise + except Exception: + logger.critical('Error has occured when running main loop, please resolve asap', exc_info=True) diff --git a/entriesadder.py b/entriesadder.py new file mode 100644 index 0000000..921334c --- /dev/null +++ b/entriesadder.py @@ -0,0 +1,44 @@ +import praw +from pokestarfansloggingsetup import setup_logger +import logging +from modules.entrylogin import reddit + +logger = setup_logger('usersubblocker') + + +def write_to_user_file(text): + with open('blockusers.txt', 'a') as file: + file.write(text) + + +def write_to_sub_file(text): + with open('blockedsubs.txt', 'a') as file: + file.write(text) + + +def strip_message(message): + try: + if message.subject == 'remove subreddit': + subreddit = reddit.subreddit(message) + mod = False + for moderator in reddit.subreddit(subreddit).moderator(): + if str(message.author) == str(moderator): + mod = True + break + if mod: + write_to_sub_file(message.body) + else: + message.reply('You are not a moderator of the subreddit so your request has not been preformed.') + elif message.subject == 'remove user': + if str(message.author) == message.body: + write_to_user_file(message.body) + else: + message.reply('You are not the OP of the submission so your request has not been preformed.') + except Exception: + logging.warning('', exc_info=True) + + +def check_for_messages(reddit): + for message in reddit.inbox.unread(mark_read=True): + strip_message(message) + reddit.inbox.mark_read(message) diff --git a/modules/footer.py b/modules/footer.py deleted file mode 100644 index 5d6c938..0000000 --- a/modules/footer.py +++ /dev/null @@ -1 +0,0 @@ -footer = '\n\n----\n\n ^^I ^^am ^^a ^^bot ^^[FAQ](https://www.reddit.com/r/DuplicatesBot/wiki/index)-[Code](https://github.com/PokestarFan/DuplicateBot)-[Bugs](https://www.reddit.com/r/DuplicatesBot/comments/6ypgmx/bugs_and_problems/)-[Suggestions](https://www.reddit.com/r/DuplicatesBot/comments/6ypg85/suggestion_for_duplicatesbot/)-[Block](https://www.reddit.com/r/DuplicatesBot/wiki/index#wiki_block_bot_from_tagging_on_your_posts)\n\n^^Now ^^you ^^can ^^remove ^^the ^^comment ^^by ^^replying ^^delete!' \ No newline at end of file diff --git a/modules/table.py b/modules/table.py new file mode 100644 index 0000000..c2bb0ef --- /dev/null +++ b/modules/table.py @@ -0,0 +1,4 @@ +from markdowntable import Table as ta + +starter = ta('Title') +starter.all_columns('Subreddit','Author','Time','Karma') \ No newline at end of file From c907186debed424a7994cbfeb938b1c0bf89c9f1 Mon Sep 17 00:00:00 2001 From: PokestarFan Date: Thu, 18 Jan 2018 18:49:23 -0500 Subject: [PATCH 12/14] Finally done --- delete.py | 47 +++++++++++++++++++++++++---------------------- duplicate.py | 22 ++++++++++------------ entriesadder.py | 18 +++++++++++++----- 3 files changed, 48 insertions(+), 39 deletions(-) diff --git a/delete.py b/delete.py index 2f6658e..4eab928 100644 --- a/delete.py +++ b/delete.py @@ -1,30 +1,33 @@ -import praw -from modules.logger import setup_logger -from modules.login import reddit -from modules.footer import footer import logging import time +from modules.logger import setup_logger +from modules.login import reddit + logger = setup_logger('user_removed_comments') def main(): - try: - for item in reddit.inbox.stream(): - logger.debug('On item {}'.format(str(item))) - try: - if 'delete' in item.body.lower(): - item.parent().delete() - logging.info('Comment {} removed'.format(str(item.parent()))) - item.author.message('Removal of comment {}'.format(str(item.parent())),'The top level post has been removed.') - except: - logging.debug('Item {} skipped'.format(str(item))) - except(KeyboardInterrupt): - raise KeyboardInterrupt - except: - logging.error('Error!', exc_info=True) - main() - + try: + for item in reddit.inbox.stream(): + logger.debug('On item {}'.format(str(item))) + try: + if 'delete' in item.body.lower() and item.author == item.submission.author: + item.parent().delete() + logging.info('Comment {} removed'.format(str(item.parent()))) + item.author.message('Removal of comment {}'.format(str(item.parent())), + 'The top level post has been removed.') + except AttributeError: + pass + except: + logging.debug('Item {} skipped'.format(str(item))) + except(KeyboardInterrupt): + raise KeyboardInterrupt + except: + logging.error('Error!', exc_info=True) + main() + + while True: - main() - time.sleep(30) \ No newline at end of file + main() + time.sleep(30) diff --git a/duplicate.py b/duplicate.py index 0b9b047..f6ba10a 100644 --- a/duplicate.py +++ b/duplicate.py @@ -3,18 +3,20 @@ import praw import prawcore +from markdowntable import Table as ta from pokestarfansloggingsetup import setup_logger from modules.login import reddit -from modules.table import starter logger = setup_logger('duplicates') # noinspection PyBroadException def generate_and_reply(submission): - footer = '\n\n----\n\n ^^I ^^am ^^a ^^bot ^^[FAQ](https://www.reddit.com/r/DuplicatesBot/wiki/index)-[' \ - 'Code](https://github.com/PokestarFan/DuplicateBot)-[Bugs](' \ + starter = ta('Title') + starter.all_columns('Subreddit', 'Author', 'Time', 'Karma') + footer = '\n\n----\n\n I am a bot [FAQ](https://www.reddit.com/r/DuplicatesBot/wiki/index)-[' \ + 'Code](https://github.com/PokestarFan/DuplicateBot)-[Bugs](' \ 'https://www.reddit.com/r/DuplicatesBot/comments/6ypgmx/bugs_and_problems/)-[Suggestions](' \ 'https://www.reddit.com/r/DuplicatesBot/comments/6ypg85/suggestion_for_duplicatesbot/)-[Block ' \ 'user (op only)' \ @@ -23,7 +25,7 @@ def generate_and_reply(submission): '={user})-[Block from subreddit (mods only)](' \ 'https://www.reddit.com/message/compose/?to=DuplicatesBotBlocker&subject=remove%20subreddit' \ '&message={sub})\n' \ - '\n^^Now ^^you ^^can ^^remove ^^the ^^comment ^^by ^^replying ^^delete! '.format(user= + '\nNow you can remove the comment by replying delete! '.format(user= str( submission.author), sub=str(submission.subreddit)) global message @@ -36,7 +38,7 @@ def generate_and_reply(submission): if str(submission.author) == author: author = author + ' [author of both threads]' duplicates.append(['[{}]({})'.format(str(dup_sub.title), 'https://www.reddit.com' + str(dup_sub.permalink)), - str(dup_sub.subreddit), author, str(time), str(dup_sub.score)]) + '/r/' + str(dup_sub.subreddit), author, str(time), str(dup_sub.score)]) if len(duplicates) > 0: message = 'Here is a list of threads in other subreddits about the same content:\n' for dup in duplicates: @@ -45,28 +47,24 @@ def generate_and_reply(submission): message += '\n' + footer try: submission.reply(message) - logger.info('Message posted on {}'.format(sub_id)) + logger.info('Message posted on {}'.format(str(submission))) logger.debug('Message: {}'.format(message)) - message = '' - except praw.exceptions.APIException: + except(praw.exceptions.APIException, UnboundLocalError): logger.debug('Submission {} has been skipped due to missing text.'.format(sub_id)) - message = '' except prawcore.exceptions.Forbidden: logger.debug('You are blocked on /r/{}'.format(str(submission.subreddit))) - message = '' except AssertionError: logger.debug('Assertion Error occured! Printing message and traceback.') logger.debug(message + str(len(message)), exc_info=True) - message = '' except(KeyboardInterrupt, SystemExit): raise except Exception: logger.error('Error occurred!', exc_info=True) - message = '' except: logger.critical( 'Massive Error occurred! Not part of the Exception, KeyboardInterrupt or SystemExit exceptions. Fix ASAP.', exc_info=True) + finally: message = '' diff --git a/entriesadder.py b/entriesadder.py index 921334c..21fa0c1 100644 --- a/entriesadder.py +++ b/entriesadder.py @@ -1,6 +1,7 @@ -import praw -from pokestarfansloggingsetup import setup_logger import logging + +from pokestarfansloggingsetup import setup_logger + from modules.entrylogin import reddit logger = setup_logger('usersubblocker') @@ -39,6 +40,13 @@ def strip_message(message): def check_for_messages(reddit): - for message in reddit.inbox.unread(mark_read=True): - strip_message(message) - reddit.inbox.mark_read(message) + try: + for message in reddit.inbox.unread(mark_read=True): + strip_message(message) + reddit.inbox.mark_read(message) + except Exception: + logging.error('error!', exc_info=True) + + +while True: + check_for_messages(reddit) From 4cc8275c166512e60d445fc2d5ab3a04240d740a Mon Sep 17 00:00:00 2001 From: PokestarFan Date: Mon, 14 May 2018 15:39:24 -0400 Subject: [PATCH 13/14] Update duplicate.py --- duplicate.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/duplicate.py b/duplicate.py index f6ba10a..abc8d7a 100644 --- a/duplicate.py +++ b/duplicate.py @@ -1,3 +1,28 @@ +# +# +# PPPPPPPPPPPPPPPPP kkkkkkkk tttt FFFFFFFFFFFFFFFFFFFFFF +# P::::::::::::::::P k::::::k ttt:::t F::::::::::::::::::::F +# P::::::PPPPPP:::::P k::::::k t:::::t F::::::::::::::::::::F +# PP:::::P P:::::P k::::::k t:::::t FF::::::FFFFFFFFF::::F +# P::::P P:::::P ooooooooooo k:::::k kkkkkkk eeeeeeeeeeee ssssssssss ttttttt:::::ttttttt aaaaaaaaaaaaa rrrrr rrrrrrrrr F:::::F FFFFFFaaaaaaaaaaaaa nnnn nnnnnnnn +# P::::P P:::::Poo:::::::::::oo k:::::k k:::::kee::::::::::::ee ss::::::::::s t:::::::::::::::::t a::::::::::::a r::::rrr:::::::::r F:::::F a::::::::::::a n:::nn::::::::nn +# P::::PPPPPP:::::Po:::::::::::::::o k:::::k k:::::ke::::::eeeee:::::eess:::::::::::::s t:::::::::::::::::t aaaaaaaaa:::::ar:::::::::::::::::r F::::::FFFFFFFFFF aaaaaaaaa:::::an::::::::::::::nn +# P:::::::::::::PP o:::::ooooo:::::o k:::::k k:::::ke::::::e e:::::es::::::ssss:::::stttttt:::::::tttttt a::::arr::::::rrrrr::::::rF:::::::::::::::F a::::ann:::::::::::::::n +# P::::PPPPPPPPP o::::o o::::o k::::::k:::::k e:::::::eeeee::::::e s:::::s ssssss t:::::t aaaaaaa:::::a r:::::r r:::::rF:::::::::::::::F aaaaaaa:::::a n:::::nnnn:::::n +# P::::P o::::o o::::o k:::::::::::k e:::::::::::::::::e s::::::s t:::::t aa::::::::::::a r:::::r rrrrrrrF::::::FFFFFFFFFF aa::::::::::::a n::::n n::::n +# P::::P o::::o o::::o k:::::::::::k e::::::eeeeeeeeeee s::::::s t:::::t a::::aaaa::::::a r:::::r F:::::F a::::aaaa::::::a n::::n n::::n +# P::::P o::::o o::::o k::::::k:::::k e:::::::e ssssss s:::::s t:::::t tttttta::::a a:::::a r:::::r F:::::F a::::a a:::::a n::::n n::::n +# PP::::::PP o:::::ooooo:::::ok::::::k k:::::ke::::::::e s:::::ssss::::::s t::::::tttt:::::ta::::a a:::::a r:::::r FF:::::::FF a::::a a:::::a n::::n n::::n +# P::::::::P o:::::::::::::::ok::::::k k:::::ke::::::::eeeeeeee s::::::::::::::s tt::::::::::::::ta:::::aaaa::::::a r:::::r F::::::::FF a:::::aaaa::::::a n::::n n::::n +# P::::::::P oo:::::::::::oo k::::::k k:::::kee:::::::::::::e s:::::::::::ss tt:::::::::::tt a::::::::::aa:::ar:::::r F::::::::FF a::::::::::aa:::a n::::n n::::n +# PPPPPPPPPP ooooooooooo kkkkkkkk kkkkkkk eeeeeeeeeeeeee sssssssssss ttttttttttt aaaaaaaaaa aaaarrrrrrr FFFFFFFFFFF aaaaaaaaaa aaaa nnnnnn nnnnnn +# +# +# +# +# +# +# import logging from datetime import datetime From 86b5c7a4cc2122f991ba1b2e81a2c16725efe1cc Mon Sep 17 00:00:00 2001 From: PokestarFan Date: Mon, 14 May 2018 15:40:26 -0400 Subject: [PATCH 14/14] Update duplicate.py --- duplicate.py | 82 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 25 deletions(-) diff --git a/duplicate.py b/duplicate.py index abc8d7a..5c6ebe8 100644 --- a/duplicate.py +++ b/duplicate.py @@ -1,28 +1,60 @@ -# -# -# PPPPPPPPPPPPPPPPP kkkkkkkk tttt FFFFFFFFFFFFFFFFFFFFFF -# P::::::::::::::::P k::::::k ttt:::t F::::::::::::::::::::F -# P::::::PPPPPP:::::P k::::::k t:::::t F::::::::::::::::::::F -# PP:::::P P:::::P k::::::k t:::::t FF::::::FFFFFFFFF::::F -# P::::P P:::::P ooooooooooo k:::::k kkkkkkk eeeeeeeeeeee ssssssssss ttttttt:::::ttttttt aaaaaaaaaaaaa rrrrr rrrrrrrrr F:::::F FFFFFFaaaaaaaaaaaaa nnnn nnnnnnnn -# P::::P P:::::Poo:::::::::::oo k:::::k k:::::kee::::::::::::ee ss::::::::::s t:::::::::::::::::t a::::::::::::a r::::rrr:::::::::r F:::::F a::::::::::::a n:::nn::::::::nn -# P::::PPPPPP:::::Po:::::::::::::::o k:::::k k:::::ke::::::eeeee:::::eess:::::::::::::s t:::::::::::::::::t aaaaaaaaa:::::ar:::::::::::::::::r F::::::FFFFFFFFFF aaaaaaaaa:::::an::::::::::::::nn -# P:::::::::::::PP o:::::ooooo:::::o k:::::k k:::::ke::::::e e:::::es::::::ssss:::::stttttt:::::::tttttt a::::arr::::::rrrrr::::::rF:::::::::::::::F a::::ann:::::::::::::::n -# P::::PPPPPPPPP o::::o o::::o k::::::k:::::k e:::::::eeeee::::::e s:::::s ssssss t:::::t aaaaaaa:::::a r:::::r r:::::rF:::::::::::::::F aaaaaaa:::::a n:::::nnnn:::::n -# P::::P o::::o o::::o k:::::::::::k e:::::::::::::::::e s::::::s t:::::t aa::::::::::::a r:::::r rrrrrrrF::::::FFFFFFFFFF aa::::::::::::a n::::n n::::n -# P::::P o::::o o::::o k:::::::::::k e::::::eeeeeeeeeee s::::::s t:::::t a::::aaaa::::::a r:::::r F:::::F a::::aaaa::::::a n::::n n::::n -# P::::P o::::o o::::o k::::::k:::::k e:::::::e ssssss s:::::s t:::::t tttttta::::a a:::::a r:::::r F:::::F a::::a a:::::a n::::n n::::n -# PP::::::PP o:::::ooooo:::::ok::::::k k:::::ke::::::::e s:::::ssss::::::s t::::::tttt:::::ta::::a a:::::a r:::::r FF:::::::FF a::::a a:::::a n::::n n::::n -# P::::::::P o:::::::::::::::ok::::::k k:::::ke::::::::eeeeeeee s::::::::::::::s tt::::::::::::::ta:::::aaaa::::::a r:::::r F::::::::FF a:::::aaaa::::::a n::::n n::::n -# P::::::::P oo:::::::::::oo k::::::k k:::::kee:::::::::::::e s:::::::::::ss tt:::::::::::tt a::::::::::aa:::ar:::::r F::::::::FF a::::::::::aa:::a n::::n n::::n -# PPPPPPPPPP ooooooooooo kkkkkkkk kkkkkkk eeeeeeeeeeeeee sssssssssss ttttttttttt aaaaaaaaaa aaaarrrrrrr FFFFFFFFFFF aaaaaaaaaa aaaa nnnnnn nnnnnn -# -# -# -# -# -# -# +# +# +# PPPPPPPPPPPPPPPPP kkkkkkkk +# P::::::::::::::::P k::::::k +# P::::::PPPPPP:::::P k::::::k +# PP:::::P P:::::P k::::::k +# P::::P P:::::P ooooooooooo k:::::k kkkkkkk eeeeeeeeeeee +# P::::P P:::::Poo:::::::::::oo k:::::k k:::::kee::::::::::::ee +# P::::PPPPPP:::::Po:::::::::::::::o k:::::k k:::::ke::::::eeeee:::::ee +# P:::::::::::::PP o:::::ooooo:::::o k:::::k k:::::ke::::::e e:::::e +# P::::PPPPPPPPP o::::o o::::o k::::::k:::::k e:::::::eeeee::::::e +# P::::P o::::o o::::o k:::::::::::k e:::::::::::::::::e +# P::::P o::::o o::::o k:::::::::::k e::::::eeeeeeeeeee +# P::::P o::::o o::::o k::::::k:::::k e:::::::e +# PP::::::PP o:::::ooooo:::::ok::::::k k:::::ke::::::::e +# P::::::::P o:::::::::::::::ok::::::k k:::::ke::::::::eeeeeeee +# P::::::::P oo:::::::::::oo k::::::k k:::::kee:::::::::::::e +# PPPPPPPPPP ooooooooooo kkkkkkkk kkkkkkk eeeeeeeeeeeeee +# SSSSSSSSSSSSSSS tttt +# SS:::::::::::::::S ttt:::t +# S:::::SSSSSS::::::S t:::::t +# S:::::S SSSSSSS t:::::t +# S:::::S ttttttt:::::ttttttt aaaaaaaaaaaaa rrrrr rrrrrrrrr +# S:::::S t:::::::::::::::::t a::::::::::::a r::::rrr:::::::::r +# S::::SSSS t:::::::::::::::::t aaaaaaaaa:::::ar:::::::::::::::::r +# SS::::::SSSSStttttt:::::::tttttt a::::arr::::::rrrrr::::::r +# SSS::::::::SS t:::::t aaaaaaa:::::a r:::::r r:::::r +# SSSSSS::::S t:::::t aa::::::::::::a r:::::r rrrrrrr +# S:::::S t:::::t a::::aaaa::::::a r:::::r +# S:::::S t:::::t tttttta::::a a:::::a r:::::r +# SSSSSSS S:::::S t::::::tttt:::::ta::::a a:::::a r:::::r +# S::::::SSSSSS:::::S tt::::::::::::::ta:::::aaaa::::::a r:::::r +# S:::::::::::::::SS tt:::::::::::tt a::::::::::aa:::ar:::::r +# SSSSSSSSSSSSSSS ttttttttttt aaaaaaaaaa aaaarrrrrrr +# FFFFFFFFFFFFFFFFFFFFFF +# F::::::::::::::::::::F +# F::::::::::::::::::::F +# FF::::::FFFFFFFFF::::F +# F:::::F FFFFFFaaaaaaaaaaaaa nnnn nnnnnnnn +# F:::::F a::::::::::::a n:::nn::::::::nn +# F::::::FFFFFFFFFF aaaaaaaaa:::::an::::::::::::::nn +# F:::::::::::::::F a::::ann:::::::::::::::n +# F:::::::::::::::F aaaaaaa:::::a n:::::nnnn:::::n +# F::::::FFFFFFFFFF aa::::::::::::a n::::n n::::n +# F:::::F a::::aaaa::::::a n::::n n::::n +# F:::::F a::::a a:::::a n::::n n::::n +# FF:::::::FF a::::a a:::::a n::::n n::::n +# F::::::::FF a:::::aaaa::::::a n::::n n::::n +# F::::::::FF a::::::::::aa:::a n::::n n::::n +# FFFFFFFFFFF aaaaaaaaaa aaaa nnnnnn nnnnnn +# +# +# +# +# +# +# import logging from datetime import datetime