-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodify_data.py
More file actions
33 lines (26 loc) · 958 Bytes
/
modify_data.py
File metadata and controls
33 lines (26 loc) · 958 Bytes
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
from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer
import json
modify_data_dict = {}
with open("./modify_data.json") as f:
modify_data_dict = json.load(f)
def get_modify_data():
return modify_data_dict
class myFileSystemEventHandler(FileSystemEventHandler):
def on_modified(self, event):
if event.src_path == "./modify_data.json":
try:
with open("./modify_data.json") as f:
data = json.load(f)
global modify_data_dict
modify_data_dict = data
print("reload ./modify_data.json")
print(get_modify_data())
except Exception as e:
print("modify format error")
pass
event_handler = myFileSystemEventHandler()
path = "."
observer = Observer()
observer.schedule(event_handler, path, recursive=False)
observer.start()