modified for use with cet and cest files

This commit is contained in:
2026-02-07 12:48:19 +01:00
parent aa49c9a7c0
commit bca5425908

View File

@@ -1,10 +1,4 @@
#!/usr/bin/env python3
# Format ACRCloud CSV/XLSX reports (Radio Stadtfilter) in das SUISA Layout
# mit korrekter Spaltenreihenfolge, automatischer Spaltenbreite,
# Fonts/Ausrichtung und sauberem Zeitformat.
# Usage: python format_radio_report.py <input.xlsx> [-o <output.xlsx>]
# Abhängigkeiten:
# pip install pandas openpyxl
from __future__ import annotations
@@ -35,13 +29,19 @@ SOURCE_MAP = {
RIGHT_ALIGN_COLS = {"Sendedatum", "Sendedauer", "Sendezeit"}
possible_cols = [
"Timestamp(UTC+01:00)",
"Timestamp(UTC+02:00)",
]
# ---------------------------------------------------------------------------
# Hilfsfunktionen
# ---------------------------------------------------------------------------
def _fmt_duration(seconds: Optional[float | int]) -> str:
"""Wandelt Sekunden (float|int|NaN) in **HH:MM:SS** um.
Excel interpretiert dann korrekt. Für Kurzzeiten 00:MM:SS"""
Excel interpretiert dann korrekt. Fuer Kurzzeiten 00:MM:SS"""
if seconds is None or pd.isna(seconds):
seconds = 0
total = int(round(float(seconds)))
@@ -51,6 +51,7 @@ def _fmt_duration(seconds: Optional[float | int]) -> str:
def _build_dataframe(src: Path) -> pd.DataFrame:
try:
df_orig = pd.read_excel(src)
except FileNotFoundError:
@@ -62,8 +63,13 @@ def _build_dataframe(src: Path) -> pd.DataFrame:
for tgt, src_col in SOURCE_MAP.items():
df_new[tgt] = df_orig.get(src_col, "")
# Datum/Zeit
ts = pd.to_datetime(df_orig.get("Timestamp(UTC+01:00)"), errors="coerce")
# Datum/Zeiti
ts_col = next(col for col in possible_cols if col in df_orig.columns)
ts = pd.to_datetime(
pd.Series(df_orig[ts_col]),
errors="coerce"
)
df_new["Sendedatum"] = ts.dt.strftime("%Y%m%d")
df_new["Sendezeit"] = ts.dt.strftime("%H:%M:%S")
@@ -124,15 +130,15 @@ def format_report(input_path: Path, output_path: Path) -> None:
df = _build_dataframe(input_path)
df.to_excel(output_path, index=False)
_autofit_and_align(output_path)
print(f"Formatiertes Reporting gespeichert{output_path}")
print(f"Formatiertes Reporting gespeichert_{output_path}")
# ---------------------------------------------------------------------------
# CLI Entry
# ---------------------------------------------------------------------------
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Format ACRCloud XLSX für SUISA")
parser.add_argument("input", help="Pfad zur OriginalXLSX (ohne/mit .xlsx)")
parser.add_argument("-o", "--output", help="Pfad der ZielXLSX")
parser = argparse.ArgumentParser(description="Format ACRCloud XLSX fuer SUISA")
parser.add_argument("input", help="Pfad zur Original XLSX (ohne/mit .xlsx)")
parser.add_argument("-o", "--output", help="Pfad der ZielXLSX")
args = parser.parse_args()
in_path = Path(args.input)