diff --git a/brancheneinstufung.py b/brancheneinstufung.py index 277df831..6e1d1c2e 100644 --- a/brancheneinstufung.py +++ b/brancheneinstufung.py @@ -653,8 +653,8 @@ def is_valid_wikipedia_article_url(wiki_url): # Komplette Funktion process_wiki_updates_from_chatgpt (Syntaxfehler behoben) def process_wiki_updates_from_chatgpt(sheet_handler, data_processor, row_limit=None): """ - Identifiziert Zeilen (S nicht OK/Updated/Copied), prüft ob U eine *valide* und *andere* Wiki-URL ist. - - Wenn ja: Kopiert U->M, markiert S='X (URL Copied)', U='URL übernommen', löscht TS/Version, setzt ReEval-Flag A. + Identifiziert Zeilen (S nicht OK/Updated/Copied/Invalid), prüft ob U eine *valide* und *andere* Wiki-URL ist. + - Wenn ja: Kopiert U->M, markiert S='X (URL Copied)', U='URL übernommen', löscht TS/Version, SETZT ReEval-Flag A='x'. - Wenn nein (U keine URL, U==M, oder U ungültig): LÖSCHT den Inhalt von U und markiert S als 'X (Invalid Suggestion)'. Verarbeitet maximal row_limit Zeilen. """ @@ -666,7 +666,7 @@ def process_wiki_updates_from_chatgpt(sheet_handler, data_processor, row_limit=N header_rows = 5 data_rows = all_data[header_rows:] - # --- Indizes holen (Korrigierte Schleife) --- + # --- Indizes holen (inkl. ReEval Flag) --- required_keys = [ "Chat Wiki Konsistenzprüfung", "Chat Vorschlag Wiki Artikel", "Wiki URL", "Wikipedia Timestamp", "Wiki Verif. Timestamp", "Timestamp letzte Prüfung", "Version", @@ -674,26 +674,18 @@ def process_wiki_updates_from_chatgpt(sheet_handler, data_processor, row_limit=N ] col_indices = {} all_keys_found = True - # --- KORRIGIERTE SCHLEIFE --- for key in required_keys: idx = COLUMN_MAP.get(key) - col_indices[key] = idx # Speichere den Index (kann auch None sein) - if idx is None: - debug_print(f"FEHLER: Schlüssel '{key}' für Spaltenindex fehlt in COLUMN_MAP!") - all_keys_found = False - # --- ENDE KORRIGIERTE SCHLEIFE --- - - if not all_keys_found: - debug_print("Breche Wiki-Updates ab, da Spaltenindizes fehlen.") - return + col_indices[key] = idx + if idx is None: debug_print(f"FEHLER: Key '{key}' fehlt!"); all_keys_found = False + if not all_keys_found: return debug_print("Breche Wiki-Updates ab.") # --- Ende Indizes holen --- all_sheet_updates = [] processed_rows_count = 0 # Zählt jetzt beide Arten von Updates updated_url_count = 0 cleared_suggestion_count = 0 - error_rows_count = 0 # Behalte Fehlerzählung bei - # wiki_scraper wird nicht mehr benötigt + # error_rows_count = 0 # Nicht mehr benötigt bei aktueller Struktur for idx, row in enumerate(data_rows): row_num_in_sheet = idx + header_rows + 1 @@ -703,13 +695,9 @@ def process_wiki_updates_from_chatgpt(sheet_handler, data_processor, row_limit=N break def get_value(key): - index = col_indices.get(key) - if index is not None and len(row) > index: return row[index] - return "" + index = col_indices.get(key); return row[index] if index is not None and len(row) > index else "" - konsistenz_s = get_value("Chat Wiki Konsistenzprüfung") - vorschlag_u = get_value("Chat Vorschlag Wiki Artikel") - url_m = get_value("Wiki URL") + konsistenz_s = get_value("Chat Wiki Konsistenzprüfung"); vorschlag_u = get_value("Chat Vorschlag Wiki Artikel"); url_m = get_value("Wiki URL") # Bedingungen prüfen is_update_candidate = False; new_url = "" @@ -724,22 +712,23 @@ def process_wiki_updates_from_chatgpt(sheet_handler, data_processor, row_limit=N new_url = vorschlag_u_cleaned condition3_u_differs_m = new_url != url_m_cleaned if condition3_u_differs_m: - # debug_print(f"Zeile {row_num_in_sheet}: Potenzieller Kandidat. Prüfe Validität von URL: {new_url}...") # Weniger Lärm - condition4_u_is_valid = is_valid_wikipedia_article_url(new_url) # Annahme: Funktion existiert - # if not condition4_u_is_valid: debug_print(f"Zeile {row_num_in_sheet}: URL '{new_url}' ist KEIN valider Artikel.") # Weniger Lärm + condition4_u_is_valid = is_valid_wikipedia_article_url(new_url) + # if not condition4_u_is_valid: debug_print(...) # Weniger Lärm is_update_candidate = condition1_status_nok and condition2_u_is_url and condition3_u_differs_m and condition4_u_is_valid - - # Behandlung ungültiger/unpassender Vorschläge clear_invalid_suggestion = condition1_status_nok and not is_update_candidate - # --- Verarbeitung des Kandidaten ODER Löschen des Vorschlags --- + # (Debugging kann bleiben) + if row_num_in_sheet in [28, 40, 42] or idx < 2: + debug_print(f"\n--- DEBUG Zeile {row_num_in_sheet} ---"); # ... (Rest Debug) ... + + # --- Verarbeitung --- if is_update_candidate: # Fall 1: Gültiges Update durchführen debug_print(f"Zeile {row_num_in_sheet}: Update-Kandidat VALIDIERUNG ERFOLGREICH. Setze ReEval-Flag und bereite Updates vor.") processed_rows_count += 1 updated_url_count += 1 - # Updates sammeln (M, S, U, Timestamps/Version löschen, A setzen) + # Updates sammeln (M, S="X (URL Copied)", U="URL übernommen", Timestamps/Version löschen, A="x") m_l=sheet_handler._get_col_letter(col_indices["Wiki URL"]+1); s_l=sheet_handler._get_col_letter(col_indices["Chat Wiki Konsistenzprüfung"]+1); u_l=sheet_handler._get_col_letter(col_indices["Chat Vorschlag Wiki Artikel"]+1); an_l=sheet_handler._get_col_letter(col_indices["Wikipedia Timestamp"]+1); ax_l=sheet_handler._get_col_letter(col_indices["Wiki Verif. Timestamp"]+1); ao_l=sheet_handler._get_col_letter(col_indices["Timestamp letzte Prüfung"]+1); ap_l=sheet_handler._get_col_letter(col_indices["Version"]+1); a_l=sheet_handler._get_col_letter(col_indices["ReEval Flag"]+1) row_updates = [ {'range': f'{m_l}{row_num_in_sheet}', 'values': [[new_url]]}, @@ -749,6 +738,7 @@ def process_wiki_updates_from_chatgpt(sheet_handler, data_processor, row_limit=N {'range': f'{ax_l}{row_num_in_sheet}', 'values': [[""]]}, {'range': f'{ao_l}{row_num_in_sheet}', 'values': [[""]]}, {'range': f'{ap_l}{row_num_in_sheet}', 'values': [[""]]}, + # --- WIEDER HINZUGEFÜGT: Setze 'x' in Spalte A --- {'range': f'{a_l}{row_num_in_sheet}', 'values': [["x"]]}, ] all_sheet_updates.extend(row_updates) @@ -756,16 +746,16 @@ def process_wiki_updates_from_chatgpt(sheet_handler, data_processor, row_limit=N elif clear_invalid_suggestion: # Fall 2: Ungültigen Vorschlag löschen/markieren debug_print(f"Zeile {row_num_in_sheet}: Status S war '{konsistenz_s}', aber Vorschlag U ('{vorschlag_u_cleaned}') ist ungültig/identisch. Lösche U und setze Status S.") - processed_rows_count += 1 # Zähle auch diese Aktion + processed_rows_count += 1 cleared_suggestion_count += 1 - # Updates sammeln (S="X (Invalid Suggestion)", U="") s_l=sheet_handler._get_col_letter(col_indices["Chat Wiki Konsistenzprüfung"]+1) u_l=sheet_handler._get_col_letter(col_indices["Chat Vorschlag Wiki Artikel"]+1) row_updates = [ - {'range': f'{s_l}{row_num_in_sheet}', 'values': [["X (Invalid Suggestion)"]]}, # Neuer Status - {'range': f'{u_l}{row_num_in_sheet}', 'values': [[""]]} # Leere Spalte U + {'range': f'{s_l}{row_num_in_sheet}', 'values': [["X (Invalid Suggestion)"]]}, + {'range': f'{u_l}{row_num_in_sheet}', 'values': [[""]]} ] all_sheet_updates.extend(row_updates) + # --- KEIN ReEval-Flag setzen --- # --- Batch Update am Ende --- if all_sheet_updates: