forked from dev-fatal/queue-notify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.py
39 lines (33 loc) · 1.32 KB
/
monitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
import time
from message import send_message
import os
class ScanFolder:
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
self.observer = Observer()
self.observer.schedule(self.event_handler, self.path, recursive=False)
self.observer.start()
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) # Delete the screenshot we created
def stop(self):
self.observer.stop()
self.observer.join()
def monitor(config):
observer = ScanFolder(config)
print("Monitoring...")
try:
while True:
time.sleep(1) # Blocking sleep so we only check every second
except:
observer.stop()