diff --git a/src/ragnar/api.py b/src/ragnar/api.py index afba59d..8819f6d 100644 --- a/src/ragnar/api.py +++ b/src/ragnar/api.py @@ -1,7 +1,9 @@ -import requests, json +import json + +import requests -from ragnar.cache import method_cache from ragnar import log +from ragnar.cache import method_cache class Api: @@ -28,7 +30,7 @@ class Api: @method_cache def login(self): - log.info("Logged in as {}".format(self.username)) + log.info(f"Logged in as {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 1359720..1d00e33 100644 --- a/src/ragnar/bot.py +++ b/src/ragnar/bot.py @@ -1,10 +1,11 @@ -from ragnar.api import Api -import time -import random -from ragnar.cache import method_cache -import re -from ragnar import log import json +import random +import re +import time + +from ragnar import log +from ragnar.api import Api +from ragnar.cache import method_cache class Bot: @@ -23,9 +24,7 @@ class Bot: "no-spam4": "Vira", } self.name = names.get(self.name, "everyone") - self.mark_text = "I am {} and downvoted this post because post is considered spam. Your message will be removed from this community site due too much downvotes. See my profile for more information. Read my source code mentioned on my profile to see what you did wrong. Should be no problem for a developer.\n\nHave a nice day!\n\n\nIf the post is not spam, please mention @retoor in the comments of this rant.".format( - self.name - ) + self.mark_text = f"I am {self.name} and downvoted this post because post is considered spam. Your message will be removed from this community site due too much downvotes. See my profile for more information. Read my source code mentioned on my profile to see what you did wrong. Should be no problem for a developer.\n\nHave a nice day!\n\n\nIf the post is not spam, please mention @retoor in the comments of this rant." self.auth = None self.triggers = [ "$", @@ -60,9 +59,9 @@ class Bot: self.rsleepii() self.auth = self.api.login() if not self.auth: - log.error("Authentication for {} failed.".format(self.username)) + log.error(f"Authentication for {self.username} failed.") raise Exception("Login error") - log.info("Authentication succesful for {}.".format(self.username)) + log.info(f"Authentication succesful for {self.username}.") def clean_rant_text(self, rant_text): return rant_text.replace(" ", "").lower() @@ -75,10 +74,10 @@ class Bot: if trigger.get("regex"): regex = trigger["regex"] if re.search(regex, clean_text): - log.info("Regex trigger {} matched!".format(regex)) + log.info(f"Regex trigger {regex} matched!") return True elif trigger in clean_text: - log.info("Trigger {} matched!".format(trigger)) + log.info(f"Trigger {trigger} matched!") return True return False @@ -102,15 +101,13 @@ class Bot: profile = self.api.get_profile(user_id) score = profile["score"] if score < 5: - log.warning( - "User {} is sus with his score of only {}.".format(username, score) - ) + log.warning(f"User {username} is sus with his score of only {score}.") return True else: return False def is_comments_sus(self, rant_id): - log.info("Checking if comments are sus of rant {}.".format(rant_id)) + log.info(f"Checking if comments are sus of rant {rant_id}.") rant = self.api.get_rant(rant_id) for comment in rant.get("comments", []): print("Checking if sus comment: ", comment["body"]) diff --git a/src/ragnar/cli.py b/src/ragnar/cli.py index b43d57a..0875417 100644 --- a/src/ragnar/cli.py +++ b/src/ragnar/cli.py @@ -1,9 +1,10 @@ import argparse -from ragnar.bot import Bot import random import time from concurrent.futures import ThreadPoolExecutor as Executor + from ragnar import log +from ragnar.bot import Bot def parse_args(): @@ -16,7 +17,7 @@ def parse_args(): def bot_task(username, password): - log.info("Created new bot runniner. Username: {}".format(username)) + log.info(f"Created new bot runniner. Username: {username}") time.sleep(random.randint(1, 20)) bot = Bot(username=username, password=password) bot.login() @@ -32,7 +33,7 @@ def main(): args = parse_args() with Executor(4) as executor: for x in range(1, 5): - username = "no-spam{}@molodetz.nl".format(str(x)) + username = f"no-spam{str(x)}@molodetz.nl" password = args.password executor.submit(bot_task, username, password) executor.shutdown(wait=True) diff --git a/src/ragnar/tests/bot.py b/src/ragnar/tests/bot.py index b041e24..0405149 100644 --- a/src/ragnar/tests/bot.py +++ b/src/ragnar/tests/bot.py @@ -1,4 +1,5 @@ import unittest + from ragnar.bot import Bot