bugfix
This commit is contained in:
@@ -575,15 +575,16 @@ def normalize_company_name(name):
|
|||||||
|
|
||||||
# NEUE Funktion für Wiki-Updates basierend auf ChatGPT Vorschlägen
|
# NEUE Funktion für Wiki-Updates basierend auf ChatGPT Vorschlägen
|
||||||
# NEUE Funktion für Wiki-Updates basierend auf ChatGPT Vorschlägen (mit Status-Update in S)
|
# NEUE Funktion für Wiki-Updates basierend auf ChatGPT Vorschlägen (mit Status-Update in S)
|
||||||
def process_wiki_updates_from_chatgpt(sheet_handler, data_processor, row_limit=None): # row_limit hinzugefügt
|
def process_wiki_updates_from_chatgpt(sheet_handler, data_processor, row_limit=None): # data_processor wird nicht mehr gebraucht
|
||||||
"""
|
"""
|
||||||
Identifiziert Zeilen, bei denen Wiki-Konsistenz (S) NICHT 'OK'/'X (Updated)' ist
|
Identifiziert Zeilen, bei denen Wiki-Konsistenz (S) NICHT 'OK'/'X (Updated)'/'X (URL Copied)' ist
|
||||||
und ein alternativer Artikel in U vorgeschlagen wurde (URL, != M).
|
und ein alternativer Artikel in U vorgeschlagen wurde (URL, != M).
|
||||||
SCHREIBT NUR die neue URL aus U nach M und markiert S als 'X (URL Copied)'.
|
Kopiert die neue URL nach M, markiert S als 'X (URL Copied)', U als 'URL übernommen'
|
||||||
Timestamps etc. werden NICHT gelöscht in diesem Schritt.
|
und LÖSCHT die Timestamps AN, AX, AO sowie die Version AP,
|
||||||
|
um eine Neuverarbeitung durch andere Modi zu ermöglichen.
|
||||||
Verarbeitet maximal row_limit Kandidaten.
|
Verarbeitet maximal row_limit Kandidaten.
|
||||||
"""
|
"""
|
||||||
debug_print("Starte Modus: Wiki-Updates Schritt 1 (URL U -> M schreiben)...")
|
debug_print("Starte Modus: Wiki-Updates Schritt 1 (URL U -> M kopieren & Timestamps löschen)...") # Angepasste Beschreibung
|
||||||
|
|
||||||
if not sheet_handler.load_data(): return
|
if not sheet_handler.load_data(): return
|
||||||
all_data = sheet_handler.get_all_data_with_headers()
|
all_data = sheet_handler.get_all_data_with_headers()
|
||||||
@@ -591,31 +592,29 @@ def process_wiki_updates_from_chatgpt(sheet_handler, data_processor, row_limit=N
|
|||||||
header_rows = 5
|
header_rows = 5
|
||||||
data_rows = all_data[header_rows:]
|
data_rows = all_data[header_rows:]
|
||||||
|
|
||||||
# Indizes holen
|
# Indizes holen (weniger benötigt jetzt, aber schadet nicht)
|
||||||
required_keys = ["Chat Wiki Konsistenzprüfung", "Chat Vorschlag Wiki Artikel", "Wiki URL"]
|
required_keys = ["Chat Wiki Konsistenzprüfung", "Chat Vorschlag Wiki Artikel", "Wiki URL",
|
||||||
|
"Wikipedia Timestamp", "Wiki Verif. Timestamp", "Timestamp letzte Prüfung", "Version"]
|
||||||
col_indices = {}
|
col_indices = {}
|
||||||
all_keys_found = True
|
all_keys_found = True
|
||||||
for key in required_keys:
|
for key in required_keys:
|
||||||
idx = COLUMN_MAP.get(key)
|
idx = COLUMN_MAP.get(key)
|
||||||
if idx is None: debug_print(f"FEHLER: Schlüssel '{key}' fehlt!"); all_keys_found = False
|
if idx is None: debug_print(f"FEHLER: Schlüssel '{key}' fehlt!"); all_keys_found = False
|
||||||
col_indices[key] = idx
|
col_indices[key] = idx
|
||||||
if not all_keys_found: return debug_print("Breche ab.")
|
if not all_keys_found: return debug_print("Breche Wiki-Updates ab.")
|
||||||
|
|
||||||
all_sheet_updates = []
|
all_sheet_updates = []
|
||||||
processed_rows_count = 0
|
processed_rows_count = 0
|
||||||
error_rows_count = 0 # Behalte Fehlerzählung bei, falls Probleme auftreten
|
# error_rows_count nicht mehr relevant hier
|
||||||
|
|
||||||
# --- Hauptschleife über Datenzeilen ---
|
|
||||||
for idx, row in enumerate(data_rows):
|
for idx, row in enumerate(data_rows):
|
||||||
row_num_in_sheet = idx + header_rows + 1
|
row_num_in_sheet = idx + header_rows + 1
|
||||||
|
|
||||||
# --- NEU: Limit prüfen ---
|
|
||||||
if row_limit is not None and processed_rows_count >= row_limit:
|
if row_limit is not None and processed_rows_count >= row_limit:
|
||||||
debug_print(f"Zeilenlimit ({row_limit}) erreicht. Breche Suche nach weiteren Kandidaten ab.")
|
debug_print(f"Zeilenlimit ({row_limit}) erreicht.")
|
||||||
break # Verlasse die for-Schleife
|
break
|
||||||
|
|
||||||
# --- Werte sicher lesen ---
|
def get_value(key): # Sicherer Zugriff
|
||||||
def get_value(key):
|
|
||||||
index = col_indices.get(key)
|
index = col_indices.get(key)
|
||||||
if index is not None and len(row) > index: return row[index]
|
if index is not None and len(row) > index: return row[index]
|
||||||
return ""
|
return ""
|
||||||
@@ -624,73 +623,52 @@ def process_wiki_updates_from_chatgpt(sheet_handler, data_processor, row_limit=N
|
|||||||
vorschlag_u = get_value("Chat Vorschlag Wiki Artikel")
|
vorschlag_u = get_value("Chat Vorschlag Wiki Artikel")
|
||||||
url_m = get_value("Wiki URL")
|
url_m = get_value("Wiki URL")
|
||||||
|
|
||||||
# --- Bedingung prüfen ---
|
# Bedingung prüfen
|
||||||
is_update_candidate = False
|
is_update_candidate = False; new_url = ""
|
||||||
new_url = ""
|
|
||||||
konsistenz_s_upper = konsistenz_s.strip().upper()
|
konsistenz_s_upper = konsistenz_s.strip().upper()
|
||||||
vorschlag_u_cleaned = vorschlag_u.strip()
|
vorschlag_u_cleaned = vorschlag_u.strip()
|
||||||
url_m_cleaned = url_m.strip()
|
url_m_cleaned = url_m.strip()
|
||||||
condition1_status_nok = konsistenz_s_upper not in ["OK", "X (UPDATED)", "X (URL COPIED)", ""] # Neuer Status hinzugefügt
|
condition1_status_nok = konsistenz_s_upper not in ["OK", "X (UPDATED)", "X (URL COPIED)", ""] # Prüft auch gegen neuen Status
|
||||||
condition2_u_is_url = vorschlag_u_cleaned.lower().startswith(("http://", "https://"))
|
condition2_u_is_url = vorschlag_u_cleaned.lower().startswith(("http://", "https://"))
|
||||||
condition3_u_differs_m = False
|
condition3_u_differs_m = False
|
||||||
if condition2_u_is_url: new_url = vorschlag_u_cleaned; condition3_u_differs_m = new_url != url_m_cleaned
|
if condition2_u_is_url: new_url = vorschlag_u_cleaned; condition3_u_differs_m = new_url != url_m_cleaned
|
||||||
is_update_candidate = condition1_status_nok and condition2_u_is_url and condition3_u_differs_m
|
is_update_candidate = condition1_status_nok and condition2_u_is_url and condition3_u_differs_m
|
||||||
|
|
||||||
# (Debugging für Zeile 28 etc. kann drin bleiben)
|
|
||||||
if row_num_in_sheet in [28, 40, 42] or idx < 2:
|
|
||||||
debug_print(f"\n--- DEBUG Zeile {row_num_in_sheet} ---"); debug_print(f" S='{konsistenz_s}' -> NOK? {condition1_status_nok}"); debug_print(f" U='{vorschlag_u}' -> URL? {condition2_u_is_url}"); debug_print(f" M='{url_m}'"); debug_print(f" U!=M? {condition3_u_differs_m}"); debug_print(f" => Update? {is_update_candidate}"); debug_print(f"--- ENDE DEBUG ---\n")
|
|
||||||
|
|
||||||
if is_update_candidate:
|
if is_update_candidate:
|
||||||
debug_print(f"Zeile {row_num_in_sheet}: Update-Kandidat gefunden. Schreibe URL '{new_url}' nach Spalte M.")
|
debug_print(f"Zeile {row_num_in_sheet}: Update-Kandidat gefunden. Kopiere URL '{new_url}' nach Spalte M und lösche Timestamps.")
|
||||||
try:
|
|
||||||
# --- Updates sammeln (NUR Spalte M und S) ---
|
# Updates sammeln (M, S, U und Timestamps/Version löschen)
|
||||||
url_m_letter = sheet_handler._get_col_letter(col_indices["Wiki URL"] + 1)
|
url_m_letter = sheet_handler._get_col_letter(col_indices["Wiki URL"] + 1)
|
||||||
konsistenz_s_letter = sheet_handler._get_col_letter(col_indices["Chat Wiki Konsistenzprüfung"] + 1)
|
konsistenz_s_letter = sheet_handler._get_col_letter(col_indices["Chat Wiki Konsistenzprüfung"] + 1)
|
||||||
vorschlag_u_letter = sheet_handler._get_col_letter(col_indices["Chat Vorschlag Wiki Artikel"] + 1) # Für "Korrektur übernommen"
|
vorschlag_u_letter = sheet_handler._get_col_letter(col_indices["Chat Vorschlag Wiki Artikel"] + 1)
|
||||||
|
ts_an_letter = sheet_handler._get_col_letter(col_indices["Wikipedia Timestamp"] + 1)
|
||||||
|
ts_ax_letter = sheet_handler._get_col_letter(col_indices["Wiki Verif. Timestamp"] + 1)
|
||||||
|
ts_ao_letter = sheet_handler._get_col_letter(col_indices["Timestamp letzte Prüfung"] + 1)
|
||||||
|
version_ap_letter = sheet_handler._get_col_letter(col_indices["Version"] + 1)
|
||||||
|
|
||||||
row_updates = [
|
row_updates = [
|
||||||
{'range': f'{url_m_letter}{row_num_in_sheet}', 'values': [[new_url]]}, # Schreibe neue URL nach M
|
{'range': f'{url_m_letter}{row_num_in_sheet}', 'values': [[new_url]]}, # Neue URL nach M
|
||||||
{'range': f'{konsistenz_s_letter}{row_num_in_sheet}', 'values': [["X (URL Copied)"]]}, # Setze neuen Status
|
{'range': f'{konsistenz_s_letter}{row_num_in_sheet}', 'values': [["X (URL Copied)"]]}, # Neuer Status in S
|
||||||
{'range': f'{vorschlag_u_letter}{row_num_in_sheet}', 'values': [["URL übernommen"]]} # Markiere Spalte U
|
{'range': f'{vorschlag_u_letter}{row_num_in_sheet}', 'values': [["URL übernommen"]]},# Markierung in U
|
||||||
|
{'range': f'{ts_an_letter}{row_num_in_sheet}', 'values': [[""]]}, # AN löschen
|
||||||
|
{'range': f'{ts_ax_letter}{row_num_in_sheet}', 'values': [[""]]}, # AX löschen
|
||||||
|
{'range': f'{ts_ao_letter}{row_num_in_sheet}', 'values': [[""]]}, # AO löschen
|
||||||
|
{'range': f'{version_ap_letter}{row_num_in_sheet}', 'values': [[""]]}, # AP löschen
|
||||||
]
|
]
|
||||||
all_sheet_updates.extend(row_updates)
|
all_sheet_updates.extend(row_updates)
|
||||||
processed_rows_count += 1
|
processed_rows_count += 1
|
||||||
# debug_print(f" -> Updates für Zeile {row_num_in_sheet} vorbereitet (nur M, S, U).")
|
# Kein Reparsing/Rebranching hier!
|
||||||
|
|
||||||
# --- Reparsing und Re-Branching HIER AUSKOMMENTIERT ---
|
# Batch Update am Ende
|
||||||
# debug_print(f" -> Reparsing Wiki-Daten für {new_url}...")
|
|
||||||
# new_wiki_data = wiki_scraper.extract_company_data(new_url)
|
|
||||||
# time.sleep(0.2)
|
|
||||||
# debug_print(f" -> Neuberechnung der Branche...")
|
|
||||||
# new_branch_result = evaluate_branche_chatgpt(...)
|
|
||||||
# time.sleep(0.2)
|
|
||||||
# --- Ende Auskommentierung ---
|
|
||||||
|
|
||||||
# --- KEINE Timestamps löschen in diesem Schritt ---
|
|
||||||
|
|
||||||
except Exception as e_row:
|
|
||||||
error_rows_count += 1
|
|
||||||
debug_print(f"FEHLER Verarbeitung Zeile {row_num_in_sheet}: {e_row}")
|
|
||||||
|
|
||||||
# --- Batch Update am Ende ---
|
|
||||||
if all_sheet_updates:
|
if all_sheet_updates:
|
||||||
debug_print(f"BEREIT ZUM SENDEN: Batch-Update für {processed_rows_count} kopierte URLs ({len(all_sheet_updates)} Zellen)...")
|
debug_print(f"BEREIT ZUM SENDEN: Batch-Update für {processed_rows_count} URL-Kopien/Timestamp-Resets ({len(all_sheet_updates)} Zellen)...")
|
||||||
if len(all_sheet_updates) > 0: debug_print(f" -> Beispiel Update 1: {all_sheet_updates[0]}")
|
|
||||||
if len(all_sheet_updates) > 2: debug_print(f" -> Beispiel Update 3: {all_sheet_updates[2]}")
|
|
||||||
success = False
|
|
||||||
try:
|
|
||||||
debug_print(" -> Rufe sheet_handler.batch_update_cells AUF...")
|
|
||||||
success = sheet_handler.batch_update_cells(all_sheet_updates)
|
success = sheet_handler.batch_update_cells(all_sheet_updates)
|
||||||
debug_print(f" -> Aufruf von sheet_handler.batch_update_cells BEENDET. Erfolg? {success}")
|
if success: debug_print(f"Sheet-Update für URL-Kopien/Resets erfolgreich.")
|
||||||
except Exception as e_update:
|
else: debug_print(f"FEHLER beim Sheet-Update für URL-Kopien/Resets.")
|
||||||
debug_print(f" -> FEHLER direkt beim Aufruf von batch_update_cells: {e_update}")
|
|
||||||
import traceback; debug_print(traceback.format_exc())
|
|
||||||
if success: debug_print(f"Sheet-Update für URL-Kopien erfolgreich.")
|
|
||||||
else: debug_print(f"FEHLER/Kein Erfolg Sheet-Update für URL-Kopien.")
|
|
||||||
else:
|
else:
|
||||||
debug_print("Keine Zeilen gefunden, für die eine URL kopiert werden muss.")
|
debug_print("Keine Zeilen gefunden, für die eine URL kopiert und Timestamps zurückgesetzt werden müssen.")
|
||||||
|
|
||||||
debug_print(f"Wiki-Updates Schritt 1 (URL U->M) abgeschlossen. {processed_rows_count} URLs kopiert, {error_rows_count} Fehler.")
|
debug_print(f"Wiki-Updates Schritt 1 abgeschlossen. {processed_rows_count} Zeilen für Neuverarbeitung vorbereitet.")
|
||||||
|
|
||||||
def extract_numeric_value(raw_value, is_umsatz=False):
|
def extract_numeric_value(raw_value, is_umsatz=False):
|
||||||
"""Extrahiert und normalisiert Zahlenwerte (Umsatz in Mio, Mitarbeiter)."""
|
"""Extrahiert und normalisiert Zahlenwerte (Umsatz in Mio, Mitarbeiter)."""
|
||||||
|
|||||||
Reference in New Issue
Block a user