diff --git a/src/ragnar/__init__.py b/src/ragnar/__init__.py index 10a02e3..06ed078 100644 --- a/src/ragnar/__init__.py +++ b/src/ragnar/__init__.py @@ -2,10 +2,10 @@ import logging import sys logging.basicConfig( - level=logging.INFO, # Adjust as needed + level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", handlers=[ - logging.StreamHandler(sys.stdout), # Log to stdout + logging.StreamHandler(sys.stdout), ] ) diff --git a/src/ragnar/api.py b/src/ragnar/api.py index 6681e0b..c875650 100644 --- a/src/ragnar/api.py +++ b/src/ragnar/api.py @@ -27,7 +27,7 @@ class Api: @method_cache def login(self): - print("New login, cache miss?") + log.info("Logged in as {}".format(self.username)) rawdata = requests.post( self.base_url + "users/auth-token", data={"username": self.username, "password": self.password, "app": 3}, diff --git a/src/ragnar/bot.py b/src/ragnar/bot.py index bea2d93..9e1eb8a 100644 --- a/src/ragnar/bot.py +++ b/src/ragnar/bot.py @@ -11,7 +11,7 @@ class Bot: self.username = username self.password = password self.name = self.username.split("@")[0] - + self.rant_history = [] names = { "no-spam": "anna", "no-spam1": "ira", @@ -49,7 +49,7 @@ class Bot: def clean_rant_text(self, rant_text): return rant_text.replace(" ", "").lower() - # @method_cache + @method_cache def is_sus_rant(self, rant_id, rant_text): clean_text = self.clean_rant_text(rant_text) for trigger in self.triggers: @@ -93,16 +93,21 @@ class Bot: self.rsleepii() rants = self.api.get_rants("recent", 5, 0) for rant in rants: + if rant['id'] in self.rant_history: + log.debug("{}: Already checked rant {}.".format(self.name,rant['id'])) + continue + else: + self.rant_history.append(rant['id']) if not self.is_user_sus(rant["user_username"]): - log.info("User {} is trusted.".format(rant["user_username"])) + log.info("{}: User {} is trusted.".format(self.name, rant["user_username"])) continue if not self.is_sus_rant(rant["id"], rant["text"]): - log.info("Rant by {} is not sus.".format(rant["user_username"])) + log.info("{}: Rant by {} is not sus.".format(self.name, rant["user_username"])) continue if self.is_flagged_as_sus(rant["id"], rant.get("num_comments")): continue - log.warning("Rant is not {} flagged as sus yet.".format(rant["user_username"])) - log.warning("Flagging rant by {} as sus.".format(rant["user_username"])) + log.warning("{}: Rant is not {} flagged as sus yet.".format(self.name,rant["user_username"])) + log.warning("{}: Flagging rant by {} as sus.".format(self.name, rant["user_username"])) self.mark_as_sus(rant) self.down_vote_rant(rant) diff --git a/src/ragnar/cli.py b/src/ragnar/cli.py index 095d022..fa1d338 100644 --- a/src/ragnar/cli.py +++ b/src/ragnar/cli.py @@ -15,7 +15,7 @@ def parse_args(): def bot_task(username, password): - log.info("Created new but task. Username: {}".format(username)) + log.info("Created new bot runniner. Username: {}".format(username)) time.sleep(random.randint(1, 20)) bot = Bot(username=username, password=password) bot.login()