-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
80 lines (65 loc) · 2.7 KB
/
main.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import os
from product import ProductApp
import threading
import sys
latest = ""
class FileEventHandler(FileSystemEventHandler):
def on_modified(self, event):
global latest
if not event.is_directory:
if event.src_path.endswith(".pdf"):
path = event.src_path.replace("\\", "/")
print("CURRENT: " + path)
if latest != path:
# The show PDF is generated by the "Show Objects" function
if path.endswith("-show.pdf"):
print("Show PDF: " + latest)
# The removed PDF is generated by the "Remove /JS Objects" function
elif path.endswith("-removed.pdf"):
print("Removed PDF: " + latest)
else:
product_app = ProductApp(path)
latest = path
print("Latest: " + latest)
def file_observer():
# Auto-detect all the downloaded pdf files in the "Downloads" directory
observer = Observer()
observer.schedule(FileEventHandler(), path=f"C:\\Users\\{os.getlogin()}\\Downloads", recursive=False)
observer.start()
try:
while True:
pass
except KeyboardInterrupt:
observer.stop()
# blocks the program execution and waits until the observer's thread is finished.
observer.join()
def manual_file_input():
global latest
print("Command line arguments:", sys.argv)
if len(sys.argv) > 1:
user_input = sys.argv[1] # Use command line argument as file path
print("Command line argument provided:", user_input)
user_input.replace("\\", "\\\\")
if user_input.endswith(".pdf"):
path = user_input.replace("\\", "/")
print("PATH:" + path)
if latest != path:
# The show PDF is generated by the "Show Objects" function
if path.endswith("-show.pdf"):
print("Show PDF: " + latest)
# The removed PDF is generated by the "Remove /JS Objects" function
elif path.endswith("-removed.pdf"):
print("Removed PDF: " + latest)
else:
product_app = ProductApp(path)
latest = path
print("Latest: " + latest)
if __name__ == "__main__":
manual_input_thread = threading.Thread(target=manual_file_input)
manual_input_thread.start()
observer_thread = threading.Thread(target=file_observer)
observer_thread.start()
manual_input_thread.join()
observer_thread.join()