123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import os
- from datetime import datetime
- from pathlib import Path
- blacklist = ["_\\", "_ori", "_.csv", "Kopie", "copy", "_sich"]
- def move(system_dir: str):
- max_age_ts = datetime.now().timestamp() - 24 * 60 * 60
- ignore_file = Path(f"{system_dir}\\IQD\\ignoriert.txt")
- ignore_list = []
- if ignore_file.exists():
- ignore_list = ignore_file.read_text(encoding="latin-1").split("\n")
- no_files = True
- for source in Path(f"{system_dir}\\IQD").rglob("*.csv"):
- if source.name in ignore_list:
- continue
- full_file = str(source)
- blacklisted = [pattern in full_file for pattern in blacklist]
- if any(blacklisted):
- continue
- no_files = False
- print("* " + str(source))
- dest = Path(f"{system_dir}\\Export\\{source.name}")
- source_size = source.stat().st_size
- source_ts = source.stat().st_mtime
- if source_size <= 20:
- print(f"!! Datei {source.name} ist leer !!")
- continue
- if source_ts < max_age_ts:
- print(f"!! Datei {source.name} ist aelter als 24 Stunden !!")
- continue
- if dest.exists():
- dest_size = dest.stat().st_size
- if source_size < dest_size // 10:
- print(f"!! Datei {source.name} ist zu klein !!")
- print(f"{source}: {source_size // 1024} KB")
- print(f"{dest}: {dest_size // 1024} KB")
- print("")
- continue
- dest_ts = dest.stat().st_mtime
- if source_ts < dest_ts:
- print(f"!! Datei {source.name} ist aelter als die Zieldatei !!")
- print(str(source) + ": " + datetime.fromtimestamp(source_ts).strftime("%d.%m.%Y, %H:%M:%S"))
- print(str(dest) + ": " + datetime.fromtimestamp(dest_ts).strftime("%d.%m.%Y, %H:%M:%S"))
- print("")
- continue
- dest.unlink()
- os.rename(source, dest)
- return no_files
- def check(system_dir: str):
- max_age_ts = datetime.now().timestamp() - 24 * 60 * 60
- ignore_file = Path(f"{system_dir}\\Export\\ignoriert.txt")
- ignore_list = []
- if ignore_file.exists():
- ignore_list = ignore_file.read_text(encoding="latin-1").split("\n")
- clean_exit = True
- for dest in Path(f"{system_dir}\\Export").glob("*.csv"):
- if dest.name in ignore_list:
- continue
- dest_ts = dest.stat().st_mtime
- if dest_ts < max_age_ts:
- print(f"!! Datei {dest.name} ist aelter als 24 Stunden !!")
- print(str(dest) + ": " + datetime.fromtimestamp(dest_ts).strftime("%d.%m.%Y, %H:%M:%S"))
- clean_exit = False
- continue
- return clean_exit
|