duplicate_checker.py aktualisiert
This commit is contained in:
@@ -172,13 +172,29 @@ def main():
|
||||
results.append({'Match':'','Score':best_score})
|
||||
logger.info(f" --> Kein Match (Score={best_score}) [Dom={dm},Name={ns},Ort={lm},Bonus={bf}]")
|
||||
|
||||
# Ergebnisse zurückschreiben (inkl. Gefundene Website)
|
||||
logger.info("Schreibe Ergebnisse ins Sheet...")
|
||||
out = pd.DataFrame(results)
|
||||
output = match_df[['CRM Name','CRM Website','Gefundene Website','CRM Ort','CRM Land']].copy()
|
||||
output = pd.concat([output.reset_index(drop=True), out], axis=1)
|
||||
data = [output.columns.tolist()] + output.values.tolist()
|
||||
if sheet.clear_and_write_data(MATCHING_SHEET_NAME, data):
|
||||
# Ergebnisse zurückschreiben (SAFE: alle Originalspalten + neue, ohne interne Normalisierungsfelder)
|
||||
logger.info("Schreibe Ergebnisse ins Sheet (SAFE in-place, keine Spaltenverluste)...")
|
||||
res_df = pd.DataFrame(results, index=match_df.index)
|
||||
write_df = match_df.copy()
|
||||
# Ergebnisse anfügen
|
||||
write_df['Match'] = res_df['Match']
|
||||
write_df['Score'] = res_df['Score']
|
||||
# Interne Arbeitsfelder entfernen
|
||||
drop_cols = ['normalized_name', 'normalized_domain', 'block_key', 'Effektive Website']
|
||||
for c in drop_cols:
|
||||
if c in write_df.columns:
|
||||
write_df.drop(columns=[c], inplace=True)
|
||||
# Lokales Backup der originalen Matching-Daten inkl. neuer Spalten
|
||||
backup_path = os.path.join(LOG_DIR, f"{now}_backup_{MATCHING_SHEET_NAME}.csv")
|
||||
try:
|
||||
write_df.to_csv(backup_path, index=False, encoding='utf-8')
|
||||
logger.info(f"Lokales Backup geschrieben: {backup_path}")
|
||||
except Exception as e:
|
||||
logger.warning(f"Backup fehlgeschlagen: {e}")
|
||||
# Schreiben
|
||||
data = [write_df.columns.tolist()] + write_df.fillna('').values.tolist()
|
||||
ok = sheet.clear_and_write_data(MATCHING_SHEET_NAME, data)
|
||||
if ok:
|
||||
logger.info("Ergebnisse erfolgreich geschrieben")
|
||||
else:
|
||||
logger.error("Fehler beim Schreiben ins Google Sheet")
|
||||
|
||||
Reference in New Issue
Block a user