Skip to content

Commit

Permalink
Added comments plus cleaner use of config in monitor.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-fatal committed Feb 11, 2023
1 parent 92203bc commit 072d8b7
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

0 comments on commit 072d8b7

Please sign in to comment.