From ee3d810cabf2a33e0b543a80945a838fcb0bb4e3 Mon Sep 17 00:00:00 2001 From: matej2 <11059438+matej2@users.noreply.github.com> Date: Thu, 16 Jan 2025 19:51:11 +0100 Subject: [PATCH] Removed manual script, refactor main --- RedditUtils.py | 5 +++++ main.py | 24 ++++++++++++++---------- manual.py | 4 ---- 3 files changed, 19 insertions(+), 14 deletions(-) delete mode 100644 manual.py diff --git a/RedditUtils.py b/RedditUtils.py index 79b8cba..309b053 100644 --- a/RedditUtils.py +++ b/RedditUtils.py @@ -81,3 +81,8 @@ def get_location_from_comment(comment: Comment): return result.group(1) else: return None + + @staticmethod + def extract_location_from_comment(comment: Comment): + inbox_item_text = comment.body + return re.search(Const.body_regex(Const.mention), inbox_item_text, flags=re.IGNORECASE) \ No newline at end of file diff --git a/main.py b/main.py index 1e4fdf6..4c09cc6 100644 --- a/main.py +++ b/main.py @@ -5,21 +5,25 @@ from const import Const -def main_stream(): +def main(): reddit_client = RedditUtils() reddit_instance = reddit_client.reddit - for item in reddit_instance.inbox.stream(): - if Const.mention.lower() in item.body.lower(): - text = item.body - result = re.search(Const.body_regex(Const.mention), text, flags=re.IGNORECASE) - if result is not None: - body = result.group(1) + for inbox_item in reddit_instance.inbox.stream(): - if reddit_client.reply_to_comment(body, item): - item.mark_read() + if Const.mention.lower() in inbox_item.body.lower(): + found_location = RedditUtils.extract_location_from_comment(inbox_item) + + if found_location is not None: + location_name = found_location.group(1) + + if reddit_client.reply_to_comment(location_name, inbox_item): + inbox_item.mark_read() else: - item.reply(Const.NOT_DETECTED) + inbox_item.reply(Const.NOT_DETECTED) sleep(10) +if __name__ == '__main__': + main() + diff --git a/manual.py b/manual.py deleted file mode 100644 index db95480..0000000 --- a/manual.py +++ /dev/null @@ -1,4 +0,0 @@ -from main import main_stream - -if __name__ == '__main__': - main_stream()