feat: Add summary page for group and family lists
- Implements a summary of registrations on page 1 for both "Kita/School" and "Family" modes. - For Kita/School mode (i/e), it lists the count of children per group/class and a total count. - For Family mode (f), it lists the count of appointments per day and a total count. - The summary block is inserted after the initial copy-and-paste info and before the detailed group/day lists. - A long separator line is added after the summary for clarity. - Page breaks are now inserted before each group/day list to ensure the summary remains on its own page at the beginning.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import csv
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
import collections
|
||||
import os.path
|
||||
import json
|
||||
@@ -16,11 +16,10 @@ TARGET_FOLDER_ID = "18DNQaH9zbcBzwhckJI-4Uah-WXTXg6bg"
|
||||
LAST_INPUT_FILE = "listen_generator_last_input.json"
|
||||
|
||||
DEFAULT_EINRICHTUNG_ODER_EVENT = "Meine Veranstaltung"
|
||||
DEFAULT_FOTODATUM_ODER_EVENTDATUM = "TT.MM.JJJJ - TT.MM.JJJJ"
|
||||
DEFAULT_FOTODATUM_ODER_EVENTDATUM = "TT.MM.JJJJ"
|
||||
DEFAULT_AUSGABEMODUS = "e"
|
||||
DEFAULT_EINRICHTUNGSTYP = "k" # k für Kindergarten, s für Schule
|
||||
DEFAULT_EINRICHTUNGSTYP = "k"
|
||||
|
||||
# Suffix nur für Kindergärten
|
||||
GRUPPENNAME_SUFFIX = "gruppe"
|
||||
|
||||
SCOPES = [
|
||||
@@ -54,7 +53,6 @@ def save_last_inputs(einrichtungstyp, einrichtung_event, datum_info, ausgabemodu
|
||||
print("Fehler beim Speichern der letzten Eingaben.")
|
||||
|
||||
def get_services_with_service_account():
|
||||
# ... (unverändert) ...
|
||||
creds = None; docs_service = None; drive_service = None
|
||||
try: creds = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
|
||||
except Exception as e: print(f"Fehler Credentials: {e}"); return None, None
|
||||
@@ -67,7 +65,6 @@ def get_services_with_service_account():
|
||||
except Exception as e: print(f"Fehler Drive Service: {e}")
|
||||
return docs_service, drive_service
|
||||
|
||||
# Die Hilfsfunktion parse_datetime_string bleibt unverändert
|
||||
def parse_datetime_string(datetime_str):
|
||||
try:
|
||||
dt_obj = datetime.strptime(datetime_str, "%d.%m.%Y %H:%M")
|
||||
@@ -75,9 +72,7 @@ def parse_datetime_string(datetime_str):
|
||||
except ValueError:
|
||||
return None, None, None
|
||||
|
||||
# --- Funktion für Modus "intern" und "extern" (Kita/Schule) ---
|
||||
def generate_kita_schule_content(docs_service, document_id_to_fill, ausgabemodus_kuerzel, einrichtungstyp_kuerzel):
|
||||
# ... (CSV-Lesen bleibt gleich) ...
|
||||
kinder_nach_gruppen = collections.defaultdict(list)
|
||||
try:
|
||||
with open(GRUPPEN_CSV_FILENAME, mode='r', encoding='utf-8-sig', newline='') as csvfile:
|
||||
@@ -85,10 +80,10 @@ def generate_kita_schule_content(docs_service, document_id_to_fill, ausgabemodus
|
||||
for row in reader:
|
||||
vorname = row.get('Vorname Kind','').strip() or row.get('Vorname','').strip()
|
||||
nachname = row.get('Nachname Kind','').strip() or row.get('Nachname','').strip()
|
||||
gruppe_original = row.get('Gruppe','').strip() or row.get('Klasse','').strip() # Flexibel auch für "Klasse" Spalte
|
||||
gruppe_original = row.get('Gruppe','').strip() or row.get('Klasse','').strip()
|
||||
if not vorname or not nachname or not gruppe_original: continue
|
||||
einzelfotos_wert = row.get('Einzelfotos', 'Nein').strip()
|
||||
gruppenfotos_wert = row.get('Gruppenfotos', 'Nein').strip()
|
||||
if not vorname or not nachname or not gruppe_original: continue
|
||||
einzelfotos_display = "✓" if einzelfotos_wert.lower() == 'ja' else "Nein"
|
||||
gruppenfotos_display = "✓" if gruppenfotos_wert.lower() == 'ja' else "Nein"
|
||||
kinder_nach_gruppen[gruppe_original].append({
|
||||
@@ -102,26 +97,38 @@ def generate_kita_schule_content(docs_service, document_id_to_fill, ausgabemodus
|
||||
kinder_nach_gruppen[gk_key].sort(key=lambda x: (x['Nachname'].lower(), x['Vorname'].lower()))
|
||||
sorted_gruppen_namen = sorted(kinder_nach_gruppen.keys())
|
||||
stand_zeit = datetime.now().strftime("%d.%m.%Y %H:%M Uhr")
|
||||
|
||||
requests = []
|
||||
col_width_nachname = 22; col_width_vorname = 22; col_width_e = 3; col_width_g = 3
|
||||
|
||||
# --- ANPASSUNG: Texte basierend auf Einrichtungstyp ---
|
||||
gruppen_spalten_header = "Klasse" if einrichtungstyp_kuerzel == 's' else "Gruppe"
|
||||
|
||||
summary_lines = ["Übersicht der Anmeldungen:", ""]
|
||||
gesamt_anmeldungen = 0
|
||||
for gruppe_name in sorted_gruppen_namen:
|
||||
anzahl = len(kinder_nach_gruppen[gruppe_name])
|
||||
summary_lines.append(f"- {gruppen_spalten_header} {gruppe_name}: {anzahl} Anmeldungen")
|
||||
gesamt_anmeldungen += anzahl
|
||||
summary_lines.append("--------------------")
|
||||
summary_lines.append(f"Gesamt: {gesamt_anmeldungen} Anmeldungen")
|
||||
summary_lines.append("\n" + "="*70 + "\n")
|
||||
|
||||
summary_text = "\n".join(summary_lines)
|
||||
requests.append({'insertText': {'endOfSegmentLocation': {}, 'text': summary_text}})
|
||||
|
||||
col_width_nachname = 22; col_width_vorname = 22; col_width_e = 3; col_width_g = 3
|
||||
erinnerungstext1 = "Dies ist die Liste der bereits angemeldeten Schüler. Bitte die noch fehlenden"
|
||||
erinnerungstext2 = "Schüler an die Anmeldung erinnern."
|
||||
if einrichtungstyp_kuerzel == 'k': # Kindergarten
|
||||
if einrichtungstyp_kuerzel == 'k':
|
||||
erinnerungstext1 = "Dies ist die Liste der bereits angemeldeten Kinder. Bitte die Eltern der noch fehlenden"
|
||||
erinnerungstext2 = "Kinder an die Anmeldung erinnern."
|
||||
# --- ENDE ANPASSUNG ---
|
||||
|
||||
for i, gruppe_original in enumerate(sorted_gruppen_namen):
|
||||
requests.append({'insertPageBreak': {'endOfSegmentLocation': {}}})
|
||||
|
||||
kinder_liste = kinder_nach_gruppen[gruppe_original]; anzahl_kinder = len(kinder_liste)
|
||||
|
||||
# --- ANPASSUNG: Suffix nur für Kindergarten ---
|
||||
gruppe_display_name = gruppe_original
|
||||
if einrichtungstyp_kuerzel == 'k':
|
||||
gruppe_display_name += GRUPPENNAME_SUFFIX
|
||||
# --- ENDE ANPASSUNG ---
|
||||
|
||||
group_block_lines = ["", ""]
|
||||
kopf_nn = "Nachname".ljust(col_width_nachname); kopf_vn = "Vorname".ljust(col_width_vorname)
|
||||
@@ -139,27 +146,22 @@ def generate_kita_schule_content(docs_service, document_id_to_fill, ausgabemodus
|
||||
group_block_lines.append(f"{nn_pad}\t{vn_pad}\t{gruppe_display_name}")
|
||||
|
||||
group_block_lines.extend(["", f"{anzahl_kinder} angemeldete Kinder", "",
|
||||
erinnerungstext1, # Angepasster Text
|
||||
erinnerungstext2, # Angepasster Text
|
||||
erinnerungstext1, erinnerungstext2,
|
||||
"", f"Stand {stand_zeit}", ""])
|
||||
|
||||
full_group_block_text = "\n".join(group_block_lines) + "\n"
|
||||
requests.append({'insertText': {'endOfSegmentLocation': {}, 'text': full_group_block_text}})
|
||||
if i < len(sorted_gruppen_namen) - 1:
|
||||
requests.append({'insertPageBreak': {'endOfSegmentLocation': {}}})
|
||||
|
||||
if requests:
|
||||
try:
|
||||
print(f"Sende Batch Update (Modus: {ausgabemodus_kuerzel}) für Doc ID '{document_id_to_fill}'...")
|
||||
print(f"Sende Batch Update (inkl. Übersicht) für Doc ID '{document_id_to_fill}'...")
|
||||
docs_service.documents().batchUpdate(documentId=document_id_to_fill, body={'requests': requests}).execute()
|
||||
print(f"Dokument erfolgreich im Modus '{ausgabemodus_kuerzel}' befüllt.")
|
||||
print(f"Dokument erfolgreich befüllt.")
|
||||
return True
|
||||
except HttpError as err: print(f"Fehler beim Befüllen: {err}"); return False
|
||||
return True
|
||||
|
||||
# --- Funktion für Modus "familie" (bleibt unverändert) ---
|
||||
def generate_familien_content(docs_service, document_id_to_fill):
|
||||
# ... (Code für diese Funktion bleibt exakt wie in der letzten Version) ...
|
||||
# (Ich füge ihn hier zur Vollständigkeit ein, aber er wurde nicht geändert)
|
||||
termine_nach_tagen = collections.defaultdict(list)
|
||||
try:
|
||||
with open(FAMILIEN_CSV_FILENAME, mode='r', encoding='utf-8-sig', newline='') as csvfile:
|
||||
@@ -183,18 +185,33 @@ def generate_familien_content(docs_service, document_id_to_fill):
|
||||
except FileNotFoundError: print(f"FEHLER: '{FAMILIEN_CSV_FILENAME}' nicht gefunden."); return False
|
||||
except Exception as e: print(f"FEHLER CSV-Lesen ('{FAMILIEN_CSV_FILENAME}'): {e}"); return False
|
||||
if not termine_nach_tagen: print(f"Keine Daten aus '{FAMILIEN_CSV_FILENAME}'."); return False
|
||||
|
||||
sorted_tage = sorted(termine_nach_tagen.keys(), key=lambda d: datetime.strptime(d, "%d.%m.%Y"))
|
||||
requests = []
|
||||
|
||||
summary_lines = ["Übersicht der Anmeldungen:", ""]
|
||||
gesamt_anmeldungen = 0
|
||||
for tag_datum_str in sorted_tage:
|
||||
anzahl = len(termine_nach_tagen[tag_datum_str])
|
||||
summary_lines.append(f"- Termine am {tag_datum_str}: {anzahl} Anmeldungen")
|
||||
gesamt_anmeldungen += anzahl
|
||||
summary_lines.append("--------------------")
|
||||
summary_lines.append(f"Gesamt: {gesamt_anmeldungen} Anmeldungen")
|
||||
summary_lines.append("\n" + "="*70 + "\n")
|
||||
|
||||
summary_text = "\n".join(summary_lines)
|
||||
requests.append({'insertText': {'endOfSegmentLocation': {}, 'text': summary_text}})
|
||||
|
||||
col_w_vn=20; col_w_nn=20; col_w_zeit=7; col_w_kinder=10; col_w_pub=5; col_w_erl=8
|
||||
for tag_idx, tag_datum_str in enumerate(sorted_tage):
|
||||
requests.append({'insertPageBreak': {'endOfSegmentLocation': {}}})
|
||||
tages_termine = sorted(termine_nach_tagen[tag_datum_str], key=lambda t: t['StartzeitObj'])
|
||||
if tag_idx > 0: requests.append({'insertPageBreak': {'endOfSegmentLocation': {}}})
|
||||
tages_block_lines = [f"Termine am {tag_datum_str}", "", ""]
|
||||
kopf_vn="Vorname".ljust(col_w_vn); kopf_nn="Nachname".ljust(col_w_nn); kopf_zeit="Uhrzeit".ljust(col_w_zeit)
|
||||
kopf_kinder="# Kinder".ljust(col_w_kinder); kopf_pub="Pub".ljust(col_w_pub); kopf_erl="Erledigt".ljust(col_w_erl)
|
||||
tages_block_lines.append(f"{kopf_vn}\t{kopf_nn}\t{kopf_zeit}\t{kopf_kinder}\t{kopf_pub}\t{kopf_erl}")
|
||||
letzte_endzeit_obj = None
|
||||
for termin_idx, termin in enumerate(tages_termine):
|
||||
for termin in tages_termine:
|
||||
if letzte_endzeit_obj and termin['StartzeitObj'] > letzte_endzeit_obj:
|
||||
leere_zeile_parts = [" ".ljust(w) for w in [col_w_vn,col_w_nn,col_w_zeit,col_w_kinder,col_w_pub,col_w_erl]]
|
||||
tages_block_lines.append("\t".join(leere_zeile_parts))
|
||||
@@ -206,9 +223,10 @@ def generate_familien_content(docs_service, document_id_to_fill):
|
||||
else: letzte_endzeit_obj = termin['StartzeitObj'] + timedelta(minutes=6)
|
||||
full_tages_block_text = "\n".join(tages_block_lines) + "\n\n"
|
||||
requests.append({'insertText': {'endOfSegmentLocation': {}, 'text': full_tages_block_text}})
|
||||
|
||||
if requests:
|
||||
try:
|
||||
print(f"Sende Batch Update (Familien Modus) für Doc ID '{document_id_to_fill}'...")
|
||||
print(f"Sende Batch Update (Familien Modus, inkl. Übersicht) für Doc ID '{document_id_to_fill}'...")
|
||||
docs_service.documents().batchUpdate(documentId=document_id_to_fill, body={'requests': requests}).execute()
|
||||
print("Dokument erfolgreich im Familien Modus befüllt.")
|
||||
return True
|
||||
@@ -218,22 +236,15 @@ def generate_familien_content(docs_service, document_id_to_fill):
|
||||
# --- Main execution block ---
|
||||
if __name__ == "__main__":
|
||||
last_einrichtungstyp, last_einrichtung_event, last_datum_info, last_ausgabemodus = get_last_inputs()
|
||||
|
||||
print("\nBitte geben Sie die Details ein:")
|
||||
|
||||
# --- ANPASSUNG: Neue Abfrage für Einrichtungstyp ---
|
||||
while True:
|
||||
user_einrichtungstyp_input = input(f"Einrichtungstyp (k=Kindergarten, s=Schule) [{last_einrichtungstyp}]: ").lower() or last_einrichtungstyp
|
||||
if user_einrichtungstyp_input in ["k", "s", "kindergarten", "schule"]:
|
||||
user_einrichtungstyp_kuerzel = user_einrichtungstyp_input[0] # Nimm immer den ersten Buchstaben
|
||||
user_einrichtungstyp_kuerzel = user_einrichtungstyp_input[0]
|
||||
break
|
||||
print("Ungültige Eingabe. Bitte 'k' oder 's' wählen.")
|
||||
# --- ENDE ANPASSUNG ---
|
||||
|
||||
user_einrichtung_event = input(f"Name der Einrichtung/Veranstaltung [{last_einrichtung_event}]: ") or last_einrichtung_event
|
||||
user_datum_info = input(f"Allgemeines Datum (für Info-Block) [{last_datum_info}]: ") or last_datum_info
|
||||
|
||||
# Die Modusabfrage (intern/extern/familie) bleibt gleich
|
||||
while True:
|
||||
user_ausgabemodus_input = input(f"Ausgabemodus (i=intern, e=extern, f=familie) [{last_ausgabemodus}]: ").lower() or last_ausgabemodus
|
||||
if user_ausgabemodus_input in ["i", "e", "f", "intern", "extern", "familie"]:
|
||||
@@ -243,15 +254,9 @@ if __name__ == "__main__":
|
||||
else: user_ausgabemodus_kuerzel = user_ausgabemodus_input
|
||||
break
|
||||
print("Ungültige Eingabe. Bitte 'i', 'e' oder 'f' wählen.")
|
||||
|
||||
# Speichere alle aktuellen Eingaben
|
||||
save_last_inputs(user_einrichtungstyp_kuerzel, user_einrichtung_event, user_datum_info, user_ausgabemodus_kuerzel)
|
||||
|
||||
GOOGLE_DOC_TITLE_DYNAMIC = f"Listen_{user_einrichtung_event.replace(' ', '_').replace(',', '')}_{user_ausgabemodus_kuerzel}_{datetime.now().strftime('%Y-%m-%d_%H-%M')}"
|
||||
|
||||
print(f"\nInfo: Erstelle Dokument '{GOOGLE_DOC_TITLE_DYNAMIC}' im Modus '{user_ausgabemodus_kuerzel}' für Typ '{user_einrichtungstyp_kuerzel}'")
|
||||
|
||||
# ... (Rest des main-Blocks bleibt gleich: Services holen, leeres Dokument erstellen, einmalige Info einfügen) ...
|
||||
docs_api_service, drive_api_service = get_services_with_service_account()
|
||||
if not docs_api_service: print("Konnte Google Docs API Service nicht initialisieren. Skript wird beendet.")
|
||||
else:
|
||||
@@ -274,9 +279,7 @@ if __name__ == "__main__":
|
||||
initial_requests = [{'insertText': {'location': {'index': 1}, 'text': initial_text}}]
|
||||
try: docs_api_service.documents().batchUpdate(documentId=document_id, body={'requests': initial_requests}).execute(); print("Einmalige Info eingefügt.")
|
||||
except HttpError as err: print(f"Fehler bei einmaliger Info: {err}")
|
||||
|
||||
success_filling = False
|
||||
# --- ANPASSUNG: Logik-Weiche ruft jetzt kita/schule Funktion auf ---
|
||||
if user_ausgabemodus_kuerzel in ["i", "e"]:
|
||||
print(f"Starte Kita/Schule-Modus ('{user_ausgabemodus_kuerzel}')...")
|
||||
success_filling = generate_kita_schule_content(docs_api_service, document_id, user_ausgabemodus_kuerzel, user_einrichtungstyp_kuerzel)
|
||||
@@ -284,8 +287,6 @@ if __name__ == "__main__":
|
||||
print("Starte Familien-Modus...")
|
||||
success_filling = generate_familien_content(docs_api_service, document_id)
|
||||
else: print(f"FEHLER: Unbekannter Ausgabemodus '{user_ausgabemodus_kuerzel}'")
|
||||
# --- ENDE ANPASSUNG ---
|
||||
|
||||
if success_filling:
|
||||
print(f"\n--- SKRIPT BEENDET ---"); print(f"Dokument-ID: {document_id}"); print(f"Link: https://docs.google.com/document/d/{document_id}/edit")
|
||||
print("HINWEIS: Text markieren und 'Einfügen > Tabelle > Tabelle aus Text erstellen...' verwenden.")
|
||||
|
||||
Reference in New Issue
Block a user