-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyncer.py
More file actions
65 lines (47 loc) · 1.77 KB
/
syncer.py
File metadata and controls
65 lines (47 loc) · 1.77 KB
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
import time
import asyncio
from label_studio_sdk import Client
from watchdog.events import PatternMatchingEventHandler
from watchdog.observers import Observer
from const import LABEL_STUDIO_URL, API_KEY
from importer import upload_img
watch_patterns = "*.py;*.txt" # 监控文件的模式
ignore_patterns = "" # 设置忽略的文件模式
ignore_directories = False # 是否忽略文件夹变化
case_sensitive = True # 是否对大小写敏感
event_handler = PatternMatchingEventHandler(
watch_patterns, ignore_patterns, ignore_directories, case_sensitive)
def on_created(event):
print(str(event.src_path) + "被创建")
asyncio.run(upload_img(event.src_path))
def on_deleted(event):
print(f"{event.src_path}被删除")
def on_modified(event):
print(f"{event.src_path} 被修改")
def on_moved(event):
print(f"{event.src_path}被移动到{event.dest_path}")
event_handler.on_created = on_created
event_handler.on_deleted = on_deleted
event_handler.on_modified = on_modified
event_handler.on_moved = on_moved
watch_path = "/home/ethanjia/dev/label-studio-pipeline/import" # 监控目录
go_recursively = True # 是否监控子文件夹
my_observer = Observer()
my_observer.schedule(event_handler, watch_path, recursive=go_recursively)
def main():
# Connect to the Label Studio API and check the connection
lbsd = Client(url=LABEL_STUDIO_URL, api_key=API_KEY)
if not lbsd.check_connection()['status'] == 'UP':
print('Connection Fails! Please try again.')
pass
else:
print('Connection Succeeds!')
my_observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
my_observer.stop()
my_observer.join()
if __name__ == '__main__':
main()