|
|
@@ -1,6 +1,9 @@
|
|
|
import os
|
|
|
import re
|
|
|
+import time
|
|
|
+from datetime import datetime
|
|
|
from enum import Enum
|
|
|
+from itertools import chain
|
|
|
from pathlib import Path
|
|
|
|
|
|
import typer
|
|
|
@@ -11,6 +14,10 @@ import config
|
|
|
from pdf import pdf_merge, pdf_test
|
|
|
|
|
|
|
|
|
+def flatten_chain(list_of_lists):
|
|
|
+ return list(chain.from_iterable(list_of_lists))
|
|
|
+
|
|
|
+
|
|
|
class ExportFormat(Enum):
|
|
|
PDF = "PDF"
|
|
|
XML = "XML"
|
|
|
@@ -27,15 +34,35 @@ def export(folder="", overwrite="0"):
|
|
|
|
|
|
|
|
|
@app.command()
|
|
|
-def reportoutput(folder="", mailcsv=""):
|
|
|
- exp = cognos11.c11_export(cfg)
|
|
|
+def reportoutput(folder="", mailcsv="", exp=None):
|
|
|
+
|
|
|
+ if re.match(r"^[\d\.\-\/]+$", folder):
|
|
|
+ return reportoutput_by_date(folder, mailcsv)
|
|
|
+
|
|
|
+ if exp is None:
|
|
|
+ exp = cognos11.c11_export(cfg)
|
|
|
+
|
|
|
# folder2 = exp.get_folder(folder)
|
|
|
req_plan = exp.get_folder_pdf_request_plan(folder)
|
|
|
merge_group = exp.get_merge_group(req_plan)
|
|
|
exp.template(req_plan, merge_group)
|
|
|
|
|
|
req_plan_filtered = exp.filter_request_plan(req_plan, f"{cfg.xml_dir}\\{mailcsv}")
|
|
|
- exp.execute_request_plan(req_plan_filtered)
|
|
|
+ req_plan_flat = flatten_chain(req_plan_filtered)
|
|
|
+ print("Exportiere Reports...")
|
|
|
+ for i in range(1, 6):
|
|
|
+ print(f"Durchlauf {i}...")
|
|
|
+ req_plan_flat = exp.execute_request_plan(req_plan_flat)
|
|
|
+ if not req_plan_flat:
|
|
|
+ break
|
|
|
+ time.sleep(20)
|
|
|
+ exp.api.login()
|
|
|
+
|
|
|
+ if req_plan_flat:
|
|
|
+ print("!! Fehler: Einige Reports konnten nicht exportiert werden !!")
|
|
|
+ for report_req in req_plan_flat:
|
|
|
+ print(Path(report_req.filename).relative_to(cfg.cognos11.reportoutput_dir))
|
|
|
+
|
|
|
if mailcsv == "":
|
|
|
pdf_test.missing_data(f"{cfg.cognos11.reportoutput_dir}\\{folder}")
|
|
|
|
|
|
@@ -44,6 +71,59 @@ def reportoutput(folder="", mailcsv=""):
|
|
|
# pdf_merge.merge_reports_in_folder(self.cfg, folder2)
|
|
|
|
|
|
|
|
|
+def reportoutput_by_date(date_str: str, mailcsv: str = "") -> None:
|
|
|
+ current_date = None
|
|
|
+ if re.match(r"^\d{4}-\d{2}-\d{2}$", date_str):
|
|
|
+ current_date = datetime.strptime(date_str, "%Y-%m-%d")
|
|
|
+ elif re.match(r"^\d{2}\.\d{2}\.\d{4}$", date_str):
|
|
|
+ current_date = datetime.strptime(date_str, "%d.%m.%Y")
|
|
|
+ elif re.match(r"^\d{2}\/\d{2}\/\d{4}$", date_str):
|
|
|
+ current_date = datetime.strptime(date_str, "%m/%d/%Y")
|
|
|
+
|
|
|
+ if current_date is None:
|
|
|
+ print(f"Ungültiges Datumsformat: {date_str}")
|
|
|
+ return
|
|
|
+
|
|
|
+ exp = cognos11.c11_export(cfg)
|
|
|
+ folders = [f["name"] for f in exp.api.get_folders()]
|
|
|
+ # for f in folders:
|
|
|
+ # print(f)
|
|
|
+
|
|
|
+ weekdays = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"]
|
|
|
+ current_weekday = weekdays[current_date.weekday()]
|
|
|
+ print(f"Berichte für {current_weekday}, {current_date.strftime('%d.%m.%Y')}...")
|
|
|
+ # taeglich
|
|
|
+ daily_interval = ["Mo-Fr", "Mo-Sa", "Mo-So", "Di-So"]
|
|
|
+ daily_interval_special = {
|
|
|
+ "Mo": ["Mo-Fr", "Mo-Sa", "Mo-So"],
|
|
|
+ "Sa": ["Mo-Sa", "Di-So"],
|
|
|
+ "So": ["Mo-So", "Di-So"]
|
|
|
+ }
|
|
|
+ current_interval = daily_interval_special.get(current_weekday, daily_interval)
|
|
|
+ for c in current_interval:
|
|
|
+ search = f"Team Content/ReportOutput/taeglich/{c}"
|
|
|
+ for f in folders:
|
|
|
+ if search in f:
|
|
|
+ print(f)
|
|
|
+ # woechentlich
|
|
|
+ search = f"Team Content/ReportOutput/woechentlich/{current_weekday}"
|
|
|
+ for f in folders:
|
|
|
+ if search in f:
|
|
|
+ print(f)
|
|
|
+ # 14-taeglich
|
|
|
+ week = (int(current_date.strftime("%W")) % 2) + 1
|
|
|
+ search = f"Team Content/ReportOutput/14-taeglich/{current_weekday}{week}"
|
|
|
+ for f in folders:
|
|
|
+ if search in f:
|
|
|
+ print(f)
|
|
|
+ # monatlich
|
|
|
+ day_of_month = current_date.strftime("%d")
|
|
|
+ search = f"Team Content/ReportOutput/monatlich/{day_of_month}"
|
|
|
+ for f in folders:
|
|
|
+ if search in f:
|
|
|
+ print(f)
|
|
|
+
|
|
|
+
|
|
|
@app.command()
|
|
|
def merge(folder="", config=""):
|
|
|
folder2 = cognos11.c11_export.get_folder(folder)
|
|
|
@@ -115,6 +195,6 @@ def version():
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
- # app()
|
|
|
+ app()
|
|
|
# reportoutput()
|
|
|
- version()
|
|
|
+ # reportoutput("2023-10-02")
|