From 072d8b7db37b4fc22fdc55578398f768d7776872 Mon Sep 17 00:00:00 2001 From: dev-fatal Date: Sat, 11 Feb 2023 16:59:50 +0000 Subject: [PATCH] Added comments plus cleaner use of config in monitor.py --- monitor.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/monitor.py b/monitor.py index 7d9811f..97c3cad 100644 --- a/monitor.py +++ b/monitor.py @@ -6,10 +6,11 @@ class ScanFolder: - def __init__(self, path, token, chat_id): - self.path = path + "\\_retail_\\Screenshots" - self.token = token - self.chat_id = chat_id + def __init__(self, config): + # Monitor the screenshots folder for any file ending in .tga + self.path = config["path"] + "\\_retail_\\Screenshots" + self.token = config["token"] + self.chat_id = config["chat_id"] self.event_handler = PatternMatchingEventHandler(patterns=["*.tga"], ignore_patterns=None, ignore_directories=False, case_sensitive=True) self.event_handler.on_created = self.on_created @@ -21,18 +22,18 @@ def on_created(self, event): send_message(self.token, self.chat_id) print("Sending message...") if os.path.exists(event.src_path): - os.remove(event.src_path) + os.remove(event.src_path) # Delete the screenshot we created def stop(self): self.observer.stop() self.observer.join() -def monitor(path, token, chat_id): - observer = ScanFolder(path, token, chat_id) +def monitor(config): + observer = ScanFolder(config) print("Monitoring...") try: while True: - time.sleep(1) - except KeyboardInterrupt: + time.sleep(1) # Blocking sleep so we only check every second + except: observer.stop()