39e578af2d
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
# Název: janssenpc_file_watch.py
|
|
# Verze: 1.1
|
|
# Datum: 2026-05-27
|
|
# Popis: Démon hlídající složku ##JNJPrenos (watchdog). Při objevení nového souboru
|
|
# spustí janssenpc_file_send.py, který zajistí přejmenování, upload a přesun do Trash.
|
|
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
from watchdog.observers import Observer
|
|
from watchdog.events import FileSystemEventHandler
|
|
|
|
SOURCE_DIR = Path(r"C:\Users\vbuzalka\OneDrive - JNJ\##JNJPrenos")
|
|
SEND_SCRIPT = Path(__file__).parent / "janssenpc_file_send.py"
|
|
|
|
|
|
def run_send():
|
|
subprocess.run([sys.executable, str(SEND_SCRIPT)], check=False)
|
|
|
|
|
|
class NewFileHandler(FileSystemEventHandler):
|
|
def on_created(self, event):
|
|
if event.is_directory:
|
|
return
|
|
run_send()
|
|
|
|
def on_moved(self, event):
|
|
if event.is_directory:
|
|
return
|
|
run_send()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Při startu zpracuj soubory, které už tam jsou
|
|
if any(f for f in SOURCE_DIR.iterdir() if f.is_file()):
|
|
run_send()
|
|
|
|
observer = Observer()
|
|
observer.schedule(NewFileHandler(), str(SOURCE_DIR), recursive=False)
|
|
observer.start()
|
|
print(f"Hlídám: {SOURCE_DIR}")
|
|
|
|
try:
|
|
while True:
|
|
time.sleep(1)
|
|
except KeyboardInterrupt:
|
|
observer.stop()
|
|
observer.join()
|