From f4cb1cb34d7d878b34bffe1442b0f5518c347057 Mon Sep 17 00:00:00 2001 From: Micah Nordland Date: Tue, 23 May 2017 22:12:49 -0400 Subject: [PATCH 01/11] Basic responder reddit bot --- redditchaosbot.py | 38 ++++++++++++++++---------------------- requirements.txt | 5 ++++- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/redditchaosbot.py b/redditchaosbot.py index e2993860..26578908 100755 --- a/redditchaosbot.py +++ b/redditchaosbot.py @@ -1,35 +1,29 @@ +import logging import praw from praw.models import MoreComments -import pprint '''Authenticated instance of Reddit''' # -------------------------------------------------------------------- # https://praw.readthedocs.io/en/latest/getting_started/installation.html # https://www.reddit.com/prefs/apps -reddit = praw.Reddit(user_agent='Chaosbot social experiment', - client_id='KbKcHMguzNRKUw', client_secret="n-2lxQYOKtJinlJUWJr_Zv7g1rw", - username='redditchaosbot', password='cha0sb0t') +reddit = praw.Reddit( + user_agent='Chaosbot social experiment', + client_id='WbDSRDEenyFRYw', + client_secret="CzAcNHiH91NM6baL1ypzQnkyFG8", + username='chaosthebotreborn', + password='9ws#?&+@3YBHLB~iVH,;5:rRr]@<,tW]J(n]t#`dZ;a7ZbsqJVny)(2yUO3d5d}VjW=L.U7aS4*E<-6x&WE$qa6>#{\Z\d]N-}T7') -reddit.read_only = True - -submission = reddit.submission(id='6criij') -subreddit = reddit.subreddit('programming') -# -------------------------------------------------------------------- +subreddit = reddit.subreddit('chaosthebot') +log = logging.getLogger("chaosbot") -'''WHAT ARE PEOPLE SAYING ABOUT CHAOSBOT?''' -# -------------------------------------------------------------------- -# in reddit thread: https://goo.gl/5ETNmF -submission.comment_sort = 'new' -top_level_comments = list(submission.comments) -newcom = top_level_comments[1] -print(newcom.body) +def process_submission(submission): + log.info("Processing", submission.title) + for comment in submission.comments: + if "hey chaosbot" in comment.body.lower(): + comment.reply("Hey {}!".format(comment.author.name)) - -'''FIND COMMENTS ABOUT CHAOS''' -# -------------------------------------------------------------------- -# TBD -# for comment in reddit.subreddit('programming').comments(limit=5): -# import pdb; pdb.set_trace() +for submission in subreddit.stream.submissions(): + process_submission(submission) diff --git a/requirements.txt b/requirements.txt index f3f2273d..6e96dc4c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,12 @@ appdirs==1.4.3 arrow==0.10.0 +emoji==0.4.5 packaging==16.8 +praw==4.5.1 +prawcore==0.10.1 pyparsing==2.2.0 python-dateutil==2.6.0 requests==2.14.2 schedule==0.4.2 six==1.10.0 -emoji==0.4.5 +update-checker==0.16 From b802e0232cca2b8a3422fbb66a323bb3959a56a2 Mon Sep 17 00:00:00 2001 From: Micah Nordland Date: Tue, 23 May 2017 22:19:51 -0400 Subject: [PATCH 02/11] Hide swp files from git repo --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f46e8887..d8082c1f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .DS_Store .venv github_pat.secret +*.swp From 1f19603aac95b89f4a2f76a92b8f36381ab9afeb Mon Sep 17 00:00:00 2001 From: Micah Nordland Date: Thu, 25 May 2017 22:27:58 -0400 Subject: [PATCH 03/11] Improved logging and an attempt is made to only reply to comments once --- .gitignore | 1 + redditchaosbot.py | 44 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index c0f4c500..7caa311f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ *.secret *.swp .vagrant/ +redditbot_replied.txt diff --git a/redditchaosbot.py b/redditchaosbot.py index 26578908..b5783286 100755 --- a/redditchaosbot.py +++ b/redditchaosbot.py @@ -1,6 +1,6 @@ import logging +import time import praw -from praw.models import MoreComments '''Authenticated instance of Reddit''' @@ -16,14 +16,42 @@ subreddit = reddit.subreddit('chaosthebot') log = logging.getLogger("chaosbot") +handler = logging.StreamHandler() +formatter = logging.Formatter( + '%(asctime)s %(name)-12s %(levelname)-8s %(message)s') +handler.setFormatter(formatter) +log.addHandler(handler) +log.setLevel(logging.INFO) -def process_submission(submission): - log.info("Processing", submission.title) - for comment in submission.comments: - if "hey chaosbot" in comment.body.lower(): - comment.reply("Hey {}!".format(comment.author.name)) +already_replied = set() +try: + with open("redditbot_replied.txt") as f: + already_replied.update(f.readlines()) +except FileNotFoundError: + pass -for submission in subreddit.stream.submissions(): - process_submission(submission) +def process_comment(comment): + log.info("Processing comment id %s", comment.id) + if comment.id not in already_replied and "hey chaosbot" in comment.body.lower(): + comment.reply("Hey {}!".format(comment.author.name)) + already_replied.add(comment.id) + + +def main(): + try: + for comment in subreddit.stream.comments(): + try: + process_comment(comment) + except praw.exceptions.APIException as ex: + sleep_time = reddit.auth.limits['reset_timestamp'] - time.time() + log.info("Sleeping for %d seconds", sleep_time) + time.sleep(sleep_time) + finally: + with open("redditbot_replied.txt", 'a') as f: + for id in already_replied: + f.write(id+"\n") + +if __name__ == "__main__": + main() From a20900f97466f1607e25abf246dbebacf414f92b Mon Sep 17 00:00:00 2001 From: Micah Nordland Date: Thu, 25 May 2017 22:49:03 -0400 Subject: [PATCH 04/11] changed bot to read from file --- redditbot.config | 5 +++++ redditchaosbot.py | 33 ++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 redditbot.config diff --git a/redditbot.config b/redditbot.config new file mode 100644 index 00000000..4a88f51f --- /dev/null +++ b/redditbot.config @@ -0,0 +1,5 @@ +{ + "client_id": "WbDSRDEenyFRYw", + "client_secret": "CzAcNHiH91NM6baL1ypzQnkyFG8", + "password": "9ws#?&+@3YBHLB~iVH,;5:rRr]@<,tW]J(n]t#`dZ;a7ZbsqJVny)(2yUO3d5d}VjW=L.U7aS4*E<-6x&WE$qa6>#{\\Z\\d]N-}T7" +} diff --git a/redditchaosbot.py b/redditchaosbot.py index b5783286..8ecaeeee 100755 --- a/redditchaosbot.py +++ b/redditchaosbot.py @@ -1,27 +1,37 @@ import logging +import json +import sys import time import praw +log = logging.getLogger("chaosbot") +handler = logging.StreamHandler() +formatter = logging.Formatter( + '%(asctime)s %(name)-12s %(levelname)-8s %(message)s') +handler.setFormatter(formatter) +log.addHandler(handler) +log.setLevel(logging.INFO) '''Authenticated instance of Reddit''' # -------------------------------------------------------------------- # https://praw.readthedocs.io/en/latest/getting_started/installation.html # https://www.reddit.com/prefs/apps + +try: + with open("redditbot.config") as config_file: + config = json.load(config_file) +except FileNotFoundError as ex: + log.critical(ex) + sys.exit(1) + reddit = praw.Reddit( user_agent='Chaosbot social experiment', - client_id='WbDSRDEenyFRYw', - client_secret="CzAcNHiH91NM6baL1ypzQnkyFG8", + client_id=config['client_id'], + client_secret=config['client_secret'], username='chaosthebotreborn', - password='9ws#?&+@3YBHLB~iVH,;5:rRr]@<,tW]J(n]t#`dZ;a7ZbsqJVny)(2yUO3d5d}VjW=L.U7aS4*E<-6x&WE$qa6>#{\Z\d]N-}T7') + password=config['password']) subreddit = reddit.subreddit('chaosthebot') -log = logging.getLogger("chaosbot") -handler = logging.StreamHandler() -formatter = logging.Formatter( - '%(asctime)s %(name)-12s %(levelname)-8s %(message)s') -handler.setFormatter(formatter) -log.addHandler(handler) -log.setLevel(logging.INFO) already_replied = set() @@ -35,6 +45,7 @@ def process_comment(comment): log.info("Processing comment id %s", comment.id) if comment.id not in already_replied and "hey chaosbot" in comment.body.lower(): + log.info("Attempting to reply to comment %s", comment.id) comment.reply("Hey {}!".format(comment.author.name)) already_replied.add(comment.id) @@ -49,7 +60,7 @@ def main(): log.info("Sleeping for %d seconds", sleep_time) time.sleep(sleep_time) finally: - with open("redditbot_replied.txt", 'a') as f: + with open("redditbot_replied.txt", 'w') as f: for id in already_replied: f.write(id+"\n") From 7b6b8646d1da38556c637bc64def5b7cd79a99fa Mon Sep 17 00:00:00 2001 From: Micah Nordland Date: Thu, 1 Jun 2017 23:56:13 -0400 Subject: [PATCH 05/11] New symmetric encryption system for config files --- encrypt_config_file.py | 23 ++++++++++++++++ encryption.py | 16 +++++++++--- symmetric_keys.py | 59 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 encrypt_config_file.py create mode 100644 symmetric_keys.py diff --git a/encrypt_config_file.py b/encrypt_config_file.py new file mode 100644 index 00000000..50f9455d --- /dev/null +++ b/encrypt_config_file.py @@ -0,0 +1,23 @@ +import sys +from cryptography.fernet import Fernet +from symmetric_keys import KeyManager + +# You gotta tell us what to call this key +try: + key_name = sys.argv[1] + file_to_encrypt = sys.argv[2] +except KeyError: + print("Usage:", sys.argv[0], "keyname file_to_encrypt") + sys.exit(1) + +# Make the symmetric key +key = Fernet.generate_key() + +with KeyManager() as key_manager: + key_manager.add_key(key_name, key) + +with open(file_to_encrypt, 'r+b') as config_file: + contents = config_file.read() + config_file.seek(0) + config_file.write(Fernet(key).encrypt(contents)) + config_file.flush() diff --git a/encryption.py b/encryption.py index 45be7a6c..e5f4c1ee 100644 --- a/encryption.py +++ b/encryption.py @@ -2,8 +2,10 @@ from cryptography.hazmat.primitives import hashes, serialization from cryptography.hazmat.primitives.asymmetric import padding, rsa +__all__ = ["encrypt", "decrypt"] -def create_decryptor(private_location, public_location): + +def create_crypto_functions(private_location, public_location): try: with open(private_location, "rb") as key_file: private_key = serialization.load_pem_private_key( @@ -32,6 +34,14 @@ def create_decryptor(private_location, public_location): ) public_file.write(pem) + def encrypt(plaintext): + return public_key.encrypt(plaintext, + padding.OAEP( + padding.MGF1(hashes.SHA1()), + hashes.SHA1(), + None + )) + def decrypt(ciphertext): return private_key.decrypt( ciphertext, @@ -42,7 +52,7 @@ def decrypt(ciphertext): ) ) - return decrypt + return encrypt, decrypt -decrypt = create_decryptor("/etc/privkey", "server/pubkey.txt") +encrypt, decrypt = create_crypto_functions("/etc/privkey", "server/pubkey.txt") diff --git a/symmetric_keys.py b/symmetric_keys.py new file mode 100644 index 00000000..9072332c --- /dev/null +++ b/symmetric_keys.py @@ -0,0 +1,59 @@ +import json +import base64 +try: + from encryption import decrypt, encrypt +except: + # We may need to encrypt when not in a server environment + from cryptography.hazmat.backends import default_backend + from cryptography.hazmat.primitives import hashes + from cryptography.hazmat.primitives.asymmetric import padding + from cryptography.hazmat.primitives.serialization import load_pem_public_key + + def encrypt(plaintext): + with open("server/pubkey.txt", "rb") as key_file: + public_key = load_pem_public_key(key_file.read(), default_backend()) + return public_key.encrypt(plaintext, + padding.OAEP( + padding.MGF1(hashes.SHA1()), + hashes.SHA1(), + None + )) + + def decrypt(ciphertext): + raise NotImplementedError("This only works in a running server env") + + +# It's a context manager y'all +class KeyManager(): + + def __init__(self, keys_file_name="symmetric_keys.json"): + self.keys_file_name = keys_file_name + self.existing_keys = {} + + # Try to load existing keys + try: + with open(keys_file_name) as keys_file: + self.existing_keys = json.load(keys_file) + except FileNotFoundError: + # Welp, aren't any + pass + + def __enter__(self): + return self + + def get_key(self, key_name): + # base64 decode the string object in the dict and decrypt and return + # base64.b64decode() returns bytes for us + return decrypt(base64.b64decode(self.existing_keys[key_name])) + + def add_key(self, key_name, key): + # encrypt the base64 encoded ASCII bytes then b64encode that + # and decode it to a Unicode string (JSON doesn't work with bytes) + # and store it + self.existing_keys[key_name] = base64.b64encode( + encrypt(key)).decode('ascii') + + def __exit__(self, exc_type, exc_value, traceback): + # Save the keys when we are finished + with open(self.keys_file_name, 'w') as keys_file: + json.dump(self.existing_keys, keys_file) From f2ffbd69050408c732c50e084a9046055b002ee1 Mon Sep 17 00:00:00 2001 From: Micah Nordland Date: Thu, 1 Jun 2017 23:57:08 -0400 Subject: [PATCH 06/11] Reddit bot's config file is encrypted now --- redditbot.config | 6 +----- redditchaosbot.py | 14 ++++++++++---- symmetric_keys.json | 1 + 3 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 symmetric_keys.json diff --git a/redditbot.config b/redditbot.config index 4a88f51f..deffb9b3 100644 --- a/redditbot.config +++ b/redditbot.config @@ -1,5 +1 @@ -{ - "client_id": "WbDSRDEenyFRYw", - "client_secret": "CzAcNHiH91NM6baL1ypzQnkyFG8", - "password": "9ws#?&+@3YBHLB~iVH,;5:rRr]@<,tW]J(n]t#`dZ;a7ZbsqJVny)(2yUO3d5d}VjW=L.U7aS4*E<-6x&WE$qa6>#{\\Z\\d]N-}T7" -} +gAAAAABZMOGlQgBCUY_ULDbssm4oJdNUXAAzY5KCHA-RDe7Ffhj3dqn73dJcy59o6FBTtQ2GC6abbkZymefNuB0nOukmdaww3Cpfc13238_E1GziwGI8OBRTtaGaNRmzKEZZ4ORcqsZEe9vxQ1njHKvHAuoM_aKb1np-2fSuzOpl9j7gzEivbH9L_dfm7cdZ4j1uQ7cxeZSzQrnolvxH3I3yXE8jpMj302TLugXE1v8SVW739aFkEps2gUMWYCO44OILLmqk0dJd3PGIxh-8RyJ3KNtsyQ_5GSsOjaSw6OQ0PQ38cwNamYyFfVxrfKQnlnginaCPrZ_IzriOwp4RBI4HKdvY3VSVGg== \ No newline at end of file diff --git a/redditchaosbot.py b/redditchaosbot.py index 19b68d9c..740af463 100755 --- a/redditchaosbot.py +++ b/redditchaosbot.py @@ -5,6 +5,8 @@ import sys import time import praw +from cryptography.fernet import Fernet +from symmetric_keys import KeyManager log = logging.getLogger("chaosbot") handler = logging.StreamHandler() @@ -20,8 +22,12 @@ # https://www.reddit.com/prefs/apps try: - with open("redditbot.config") as config_file: - config = json.load(config_file) + with open("redditbot.config", 'rb') as config_file: + with KeyManager() as key_manager: + key = key_manager.get_key("redditchaosbot") + fernet = Fernet(key) + config = json.loads(fernet.decrypt(config_file.read()).decode('utf-8')) + print(config) except FileNotFoundError as ex: log.critical(ex) sys.exit(1) @@ -31,7 +37,7 @@ client_id=config['client_id'], client_secret=config['client_secret'], username='chaosthebotreborn', - password=config['password']) + password=config['password']) subreddit = reddit.subreddit('chaosthebot') @@ -57,7 +63,7 @@ def main(): for comment in subreddit.stream.comments(): try: process_comment(comment) - except praw.exceptions.APIException as ex: + except praw.exceptions.APIException: sleep_time = reddit.auth.limits['reset_timestamp'] - time.time() log.info("Sleeping for %d seconds", sleep_time) time.sleep(sleep_time) diff --git a/symmetric_keys.json b/symmetric_keys.json new file mode 100644 index 00000000..1f9ea5cd --- /dev/null +++ b/symmetric_keys.json @@ -0,0 +1 @@ +{"redditchaosbot": "UDDNlQBgfgU6jVRnEX/clFnAfpruABFx99pp08CV4jYRUyrcsbQ4uk3RecpX+QGPCTOlbErKr+QCo0V6QRd3rRX1weytQSzg6J1E4WGWhk6qkTOKnqiQodtmK+xU9q8mOtG/pVLUbB2MwjdZpefwUHYkRHpfRS8++dB8jy834Q2QKvWWJXbJhIMYgvoDAy2LRljmEMToVpgushU9b5n4cPghAEdp7cUpP6SPJ8ZykUpza+PLuThyZZGwgygrRlBV8exjdGRKFeNFSibkv3plhHRHisdYYBKfB8m4KzYI+GsBWuRY36mQL6ZTVh3SpkAsvwTWb0XHUxEgII37Q3A9HA=="} \ No newline at end of file From e02c1580945ce87ab4008572637c447b89865d06 Mon Sep 17 00:00:00 2001 From: Micah Nordland Date: Fri, 2 Jun 2017 21:40:06 -0400 Subject: [PATCH 07/11] redditbot proces managed by chaos.py, replied file is json now --- .gitignore | 2 +- chaos.py | 4 ++++ redditchaosbot.py | 27 ++++++++++++++++++--------- requirements.txt | 19 ++++++++++++------- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index d4301e0b..69b56f74 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ *~ .DS_Store .vagrant/ -redditbot_replied.txt +redditbot_replied.json .venv __pycache__ github_pat.secret diff --git a/chaos.py b/chaos.py index 35909048..fdecebd7 100644 --- a/chaos.py +++ b/chaos.py @@ -51,10 +51,14 @@ def main(): log.info("starting up and entering event loop") os.system("pkill chaos_server") + os.system("pkill chaos_redditbot") server_dir = join(dirname(abspath(__file__)), "server") subprocess.Popen([sys.executable, "server.py"], cwd=server_dir) + #Start Reddit bot + subprocess.Popen([sys.executable, "redditchaosbot.py"]) + # Schedule all cron jobs to be run cron.schedule_jobs(api) diff --git a/redditchaosbot.py b/redditchaosbot.py index 740af463..77ee9455 100755 --- a/redditchaosbot.py +++ b/redditchaosbot.py @@ -4,11 +4,14 @@ import json import sys import time +from atomicwrites import atomic_write import praw from cryptography.fernet import Fernet from symmetric_keys import KeyManager +from server.server import set_proc_name -log = logging.getLogger("chaosbot") +set_proc_name("chaos_redditbot") +log = logging.getLogger("chaos_redditbot") handler = logging.StreamHandler() formatter = logging.Formatter( '%(asctime)s %(name)-12s %(levelname)-8s %(message)s') @@ -27,7 +30,6 @@ key = key_manager.get_key("redditchaosbot") fernet = Fernet(key) config = json.loads(fernet.decrypt(config_file.read()).decode('utf-8')) - print(config) except FileNotFoundError as ex: log.critical(ex) sys.exit(1) @@ -43,19 +45,27 @@ already_replied = set() +replied_file = "redditbot_replied.json" try: - with open("redditbot_replied.txt") as f: - already_replied.update(f.readlines()) -except FileNotFoundError: + with open(replied_file) as f: + already_replied.update(json.load(f)['already_replied']) +except: pass +def save_already_replied(replied_list): + with atomic_write(replied_file, overwrite=True) as f: + json.dump({'already_replied': list(replied_list)}, f) + + def process_comment(comment): log.info("Processing comment id %s", comment.id) if comment.id not in already_replied and "hey chaosbot" in comment.body.lower(): log.info("Attempting to reply to comment %s", comment.id) comment.reply("Hey {}!".format(comment.author.name)) already_replied.add(comment.id) + # Save every chance we get + save_already_replied(already_replied) def main(): @@ -64,13 +74,12 @@ def main(): try: process_comment(comment) except praw.exceptions.APIException: + # Save every chance we get + save_already_replied(already_replied) sleep_time = reddit.auth.limits['reset_timestamp'] - time.time() log.info("Sleeping for %d seconds", sleep_time) time.sleep(sleep_time) finally: - with open("redditbot_replied.txt", 'w') as f: - for id in already_replied: - f.write(id+"\n") - + save_already_replied(already_replied) if __name__ == "__main__": main() diff --git a/requirements.txt b/requirements.txt index 1b0af154..0f258e56 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,24 +1,30 @@ ansible==2.3.0.0 appdirs==1.4.3 arrow==0.10.0 -emoji==0.4.5 -packaging==16.8 -praw==4.5.1 -prawcore==0.10.1 asn1crypto==0.22.0 +atomicwrites==1.1.5 +certifi==2017.4.17 cffi==1.10.0 +chardet==3.0.3 cryptography==1.9 emoji==0.4.5 enum34==1.1.6 +flake8==3.3.0 idna==2.5 ipaddress==1.0.18 Jinja2==2.9.6 MarkupSafe==1.0 +mccabe==0.6.1 packaging==16.8 paramiko==2.1.2 +praw==4.5.1 +prawcore==0.10.1 pyasn1==0.2.3 +pycodestyle==2.3.1 pycparser==2.17 pycrypto==2.6.1 +pyflakes==1.5.0 +PyMySQL==0.7.11 pyparsing==2.2.0 python-dateutil==2.6.0 PyYAML==3.12 @@ -26,7 +32,6 @@ requests==2.17.3 schedule==0.4.2 sh==1.12.13 six==1.10.0 -update-checker==0.16 -flake8==3.3.0 unidiff==0.5.4 -pymysql +update-checker==0.16 +urllib3==1.21.1 From d8b6eba42e94b6d6f0301ccd8f62a34c5527a9cb Mon Sep 17 00:00:00 2001 From: Micah Nordland Date: Fri, 2 Jun 2017 21:45:02 -0400 Subject: [PATCH 08/11] re-encrypted config file with actual server's pubkey --- redditbot.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redditbot.config b/redditbot.config index deffb9b3..d5b6a4e0 100644 --- a/redditbot.config +++ b/redditbot.config @@ -1 +1 @@ -gAAAAABZMOGlQgBCUY_ULDbssm4oJdNUXAAzY5KCHA-RDe7Ffhj3dqn73dJcy59o6FBTtQ2GC6abbkZymefNuB0nOukmdaww3Cpfc13238_E1GziwGI8OBRTtaGaNRmzKEZZ4ORcqsZEe9vxQ1njHKvHAuoM_aKb1np-2fSuzOpl9j7gzEivbH9L_dfm7cdZ4j1uQ7cxeZSzQrnolvxH3I3yXE8jpMj302TLugXE1v8SVW739aFkEps2gUMWYCO44OILLmqk0dJd3PGIxh-8RyJ3KNtsyQ_5GSsOjaSw6OQ0PQ38cwNamYyFfVxrfKQnlnginaCPrZ_IzriOwp4RBI4HKdvY3VSVGg== \ No newline at end of file +gAAAAABZMhR4ejTZdcGI3-W4ANpPk9EfyiQP71Nafrj0YLyFML1yctx_tzEeJcXT9-9Tp51z9hD0aDos7ivXFOlth7sRlDojY6-v-2T3_-wv3_jfTpQNV4zxfkzrKFVDRX4kVcNhu6YkkORAcJZu_5aNgCNBTGh2tQjG4WVIfvvCx-2RyP5TKOFC5CPSMlVvTqeaau4GbK2Qk7ZJq6oMCI00z5jSeRQW2Uh87zKnvu_HZicxDIjTIJfNP0bTxB08eLcjP5hr4cNqDSkc0-JOIvaPB721intWDuoLVLCragfz56utKslMD3gIDeCsevAUov6tN8b0qYYjJctk0PpWn-TXuxDFXZ8-mRswJbfbQZVWJN4bH84NX2oaAUgan6qclkAMu12VovlMX5dJd_LdmcA2Q_sWIsJlJIdrAtVA8Lrvow8RJ13BQi3tjeV_3g6VD5G0PhJ0HrGPCURTczuXYIpkyKfKXBpU0PnePMjKIf4izUeeBprQQk-ozvGRMBMAlldUtZd91wGY1An6ULrY5fPBWSankJTZdUJG9cM309LSCYZaUgLZWMw= \ No newline at end of file From 59cc3632ca627427ebfce95620f3114a1269cdc2 Mon Sep 17 00:00:00 2001 From: Micah Nordland Date: Fri, 2 Jun 2017 22:11:27 -0400 Subject: [PATCH 09/11] forgot to add the updated symmetric_keys.json --- symmetric_keys.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/symmetric_keys.json b/symmetric_keys.json index 1f9ea5cd..faba373d 100644 --- a/symmetric_keys.json +++ b/symmetric_keys.json @@ -1 +1 @@ -{"redditchaosbot": "UDDNlQBgfgU6jVRnEX/clFnAfpruABFx99pp08CV4jYRUyrcsbQ4uk3RecpX+QGPCTOlbErKr+QCo0V6QRd3rRX1weytQSzg6J1E4WGWhk6qkTOKnqiQodtmK+xU9q8mOtG/pVLUbB2MwjdZpefwUHYkRHpfRS8++dB8jy834Q2QKvWWJXbJhIMYgvoDAy2LRljmEMToVpgushU9b5n4cPghAEdp7cUpP6SPJ8ZykUpza+PLuThyZZGwgygrRlBV8exjdGRKFeNFSibkv3plhHRHisdYYBKfB8m4KzYI+GsBWuRY36mQL6ZTVh3SpkAsvwTWb0XHUxEgII37Q3A9HA=="} \ No newline at end of file +{"redditchaosbot": "XZNtqEBHjid0OdZ+jlgV6fUnuVBH9OjAVpM1KCJ8/WXEniFLilENgji2KfS+ZRVLevojcimhR2vMYPhCTi8ogZw4aqenvb1s+oDmSJ1F+wk8P8B3wdULoamg5ccM+4xANQyptsV5WJSqR1hfqoAMYIsXSR4O/gbArl9ga0dkQJRGs7aQvMqz22bSw+LI3fnuhyqi5fT0KZmCrotMptig/ocQcBuZoVraWAfrTyLzCKEp0aAHmRncdOAr2pqRCwNpcCNV19ScofYEcakLav5vA7XOSVIx9hRWQbBNfJPCSCZBy69VqGU8N+Jf9IILyCh3Q1HgiN7Ho1kY5roA344gAg=="} \ No newline at end of file From 0de74a57377d613718480b36c7927768413a09b0 Mon Sep 17 00:00:00 2001 From: Micah Nordland Date: Fri, 2 Jun 2017 22:14:52 -0400 Subject: [PATCH 10/11] Fixed style errors --- chaos.py | 20 +++++++++++++------- redditchaosbot.py | 2 ++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/chaos.py b/chaos.py index a5222265..1abc2fc1 100644 --- a/chaos.py +++ b/chaos.py @@ -32,6 +32,7 @@ class LessThanFilter(logging.Filter): """ Source: https://stackoverflow.com/questions/2302315 """ + def __init__(self, exclusive_maximum, name=""): super(LessThanFilter, self).__init__(name) self.max_level = exclusive_maximum @@ -52,10 +53,13 @@ def main(): logging_handler_err = logging.StreamHandler(sys.stderr) logging_handler_err.setLevel(settings.LOG_LEVEL_ERR) - logging.basicConfig(level=logging.NOTSET, - format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', - datefmt='%m-%d %H:%M', - handlers=[logging_handler_out, logging_handler_err]) + logging.basicConfig( + level=logging.NOTSET, + format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', + datefmt='%m-%d %H:%M', + handlers=[ + logging_handler_out, + logging_handler_err]) logging.getLogger("requests").propagate = False logging.getLogger("sh").propagate = False @@ -81,13 +85,14 @@ def main(): server_dir = join(dirname(abspath(__file__)), "server") subprocess.Popen([sys.executable, "server.py"], cwd=server_dir) - #Start Reddit bot + # Start Reddit bot subprocess.Popen([sys.executable, "redditchaosbot.py"]) # Schedule all cron jobs to be run cron.schedule_jobs(api) - log.info("Setting description to {desc}".format(desc=settings.REPO_DESCRIPTION)) + log.info("Setting description to {desc}".format( + desc=settings.REPO_DESCRIPTION)) github_api.repos.set_desc(api, settings.URN, settings.REPO_DESCRIPTION) log.info("Ensure creation of issue/PR labels") @@ -122,7 +127,8 @@ def check_for_prev_crash(api, log): # Currently, I'm just reading the last 200 lines... which I think # ought to be enough, but if anyone has a better way to do this, # please do it. - dump = subprocess.check_output(["tail", "-n", "200", settings.CHAOSBOT_STDERR_LOG]) + dump = subprocess.check_output( + ["tail", "-n", "200", settings.CHAOSBOT_STDERR_LOG]) # Create a github issue for the problem title = "Help! I crashed! --CB" diff --git a/redditchaosbot.py b/redditchaosbot.py index 77ee9455..a50eec7c 100755 --- a/redditchaosbot.py +++ b/redditchaosbot.py @@ -81,5 +81,7 @@ def main(): time.sleep(sleep_time) finally: save_already_replied(already_replied) + + if __name__ == "__main__": main() From c506d8436fba7e89bd1f85f46d4c61188f8c2e4b Mon Sep 17 00:00:00 2001 From: Micah Nordland Date: Fri, 2 Jun 2017 22:17:32 -0400 Subject: [PATCH 11/11] More style fixes --- chaos.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chaos.py b/chaos.py index 1abc2fc1..7779d77c 100644 --- a/chaos.py +++ b/chaos.py @@ -59,7 +59,8 @@ def main(): datefmt='%m-%d %H:%M', handlers=[ logging_handler_out, - logging_handler_err]) + logging_handler_err + ]) logging.getLogger("requests").propagate = False logging.getLogger("sh").propagate = False