Skip to content

Commit

Permalink
Removed manual script, refactor main
Browse files Browse the repository at this point in the history
  • Loading branch information
matej2 committed Jan 16, 2025
1 parent 3e30649 commit ee3d810
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
5 changes: 5 additions & 0 deletions RedditUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
24 changes: 14 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

4 changes: 0 additions & 4 deletions manual.py

This file was deleted.

0 comments on commit ee3d810

Please sign in to comment.