Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.6 kB
2
Indexable
Never
import win10toast_click
import time
import subprocess
import os
import glob
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
src="D:/temp"
toaster = win10toast_click.ToastNotifier()


def on_modified(event):
    list_of_files = glob.glob(src + "/*")
    latest_file = max(list_of_files, key=os.path.getmtime)

    list_of_files1=glob.glob(latest_file + "/*")
    latest_file1=max(list_of_files1, key=os.path.getmtime)

    list_of_files2 = glob.glob(latest_file1 + "/*")
    latest_file2 = max(list_of_files2, key=os.path.getmtime)

    toaster.show_toast("Объект создан", latest_file1[len(latest_file) + 1:] + " экспортировал " + latest_file2[len(latest_file1) + 1:] + " в папку " + latest_file[len(src) + 1:],duration=10,callback_on_click=papka)
def papka():
    list_of_files = glob.glob(src + "/*")
    latest_file = max(list_of_files, key=os.path.getmtime)

    list_of_files1=glob.glob(latest_file + "/*")
    latest_file1=max(list_of_files1, key=os.path.getmtime)

    list_of_files2 = glob.glob(latest_file1 + "/*")
    latest_file2 = max(list_of_files2, key=os.path.getmtime)
    os.startfile(latest_file1)

if __name__=='__main__':

    event_handler = FileSystemEventHandler()
    event_handler.on_modified=on_modified
    observer = Observer()
    observer.schedule(event_handler, src, recursive=True)
    observer.start()

try:
    print('start')
    while True:
        time.sleep(1)

except KeyboardInterrupt:
    observer.stop()
    observer.join()
    print('stop')