فهرست منبع

Tools für S+K

gc-server3 6 ماه پیش
والد
کامیت
d20fab087e
2فایلهای تغییر یافته به همراه63 افزوده شده و 0 حذف شده
  1. 27 0
      tasks_tools/copy_and_import.py
  2. 36 0
      tasks_tools/wait.py

+ 27 - 0
tasks_tools/copy_and_import.py

@@ -0,0 +1,27 @@
+import calendar
+import datetime
+
+import typer
+
+filename = "test.csv"
+archive_folder = "Archiv"
+
+
+def main():
+    today = datetime.datetime.now().date()
+    end_of_month = last_day_of_month(today)
+
+    last_month = today - datetime.timedelta(days=30)
+    end_of_last_month = last_day_of_month(last_month)
+
+    if today == end_of_month:
+        archive_filename = archive_folder + "\\" + filename[:-4] + "_" + today.isoformat() + filename[-4:]
+
+
+def last_day_of_month(any_date: datetime.date) -> datetime.date:
+    end_of_month = calendar.monthrange(any_date.year, any_date.month)[2]
+    return datetime.date(any_date.year, any_date.month, end_of_month)
+
+
+if __name__ == "__main__":
+    typer.run(main)

+ 36 - 0
tasks_tools/wait.py

@@ -0,0 +1,36 @@
+import time
+from datetime import datetime, timedelta
+from pathlib import Path
+
+import typer
+
+
+def main(filename: str, tolerance: int = 12, duration: int = 6):
+    now_ts = datetime.now()
+    max_ts = now_ts + timedelta(hours=duration)
+    file_mtime_ts = datetime.fromtimestamp(Path(filename).stat().st_mtime)
+
+    print(f"Warte auf Datei {filename}")
+    print("Aktuelle Uhrzeit:   " + now_ts.strftime("%d.%m.%Y %H:%M:%S"))
+    print("Aenderungsdatum:    " + file_mtime_ts.strftime("%d.%m.%Y %H:%M:%S"))
+    print("Maximale Wartezeit: " + max_ts.strftime("%d.%m.%Y %H:%M:%S"))
+    print("")
+
+    while now_ts < max_ts:
+        now_ts = datetime.now()
+        file_mtime_ts = datetime.fromtimestamp(Path(filename).stat().st_mtime)
+
+        oldest_ts = now_ts - timedelta(hours=tolerance)
+        newest_ts = now_ts - timedelta(minutes=10)
+
+        if file_mtime_ts >= oldest_ts and file_mtime_ts <= newest_ts:
+            print(f"\nDatei {filename} ist bereit")
+            return
+        print(".", end="")
+        time.sleep(60)
+    print(f"\n!! Datei {filename} ist nicht aktuell. Warten beendet !!")
+    exit(1)
+
+
+if __name__ == "__main__":
+    typer.run(main)