34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
import pandas as pd
|
|
import json
|
|
import os
|
|
import re
|
|
|
|
root_dir = "exel_datein"
|
|
date_pattern = re.compile(r'(\d{4})[\\/](\d{2})')
|
|
|
|
all_notes = []
|
|
|
|
for dirpath, _, filenames in os.walk(root_dir):
|
|
match = date_pattern.search(dirpath)
|
|
if not match:
|
|
continue
|
|
jahr, monat = match.groups()
|
|
for filename in filenames:
|
|
if filename.lower().endswith(('.xlsx', '.xls')):
|
|
excel_path = os.path.join(dirpath, filename)
|
|
try:
|
|
df = pd.read_excel(excel_path, sheet_name=0, usecols=[0, 1], names=["Kunde", "Info"])
|
|
df = df.dropna(subset=["Kunde", "Info"])
|
|
for _, row in df.iterrows():
|
|
# Format: Kunde: Info (Jahr: xxxx, Monat: xx)
|
|
note = f"{row['Kunde']}: {row['Info']} (Jahr: {jahr}, Monat: {monat})"
|
|
all_notes.append(note)
|
|
print(f"Verarbeitet: {excel_path}")
|
|
except Exception as e:
|
|
print(f"Fehler bei {excel_path}: {e}")
|
|
|
|
# Alles als JSON speichern
|
|
with open("background_data.json", "w", encoding="utf-8") as f:
|
|
json.dump(all_notes, f, ensure_ascii=False, indent=2)
|
|
|
|
print("Alle Daten erfolgreich als background_data.json gespeichert.") |