Refactor process_row function to streamline row processing and error handling

This commit is contained in:
2025-10-29 21:30:04 +01:00
parent 2eb1b38f25
commit fd75bc88dc

91
main.py
View File

@@ -65,6 +65,52 @@ def get_finish_type(row_data):
return None
def process_row(row, mayo, counter):
"""Processes a single row from the sheet."""
if len(row) < 3:
return None # Skip rows with insufficient columns
link = row[1]
nr_zam = row[2]
if not link:
return None
print(f"\n🔗 Sprawdzam: {link}")
try:
info = mayo.get_order_info(link)
order_number = info["order_number"]
model = info["model"]
print(f"Nr z arkusza: {nr_zam}")
print(f"Nr ze strony: {order_number}")
print(f"Model: {model}")
if normalize(order_number) == normalize(nr_zam):
print("✅ Numer się zgadza")
else:
print("⚠️ Numer NIE pasuje!")
row_data = [
counter,
link,
nr_zam,
model,
get_finish_type(info),
info.get("color_top"),
info.get("color_body"),
info.get("color_neck"),
info.get("color_head"),
info.get("finish_kc"),
info.get("finish_s"),
]
print(f"raw_data: {row_data}")
return row_data
except Exception as e:
print(f"❌ Błąd podczas przetwarzania linku {link}: {e}")
return None
def main():
# Inicjalizuj API raz na początku
gsheet_api = GSheetAPI()
@@ -94,50 +140,11 @@ def main():
counter = 1
# Zakładamy: kolumna B = link, kolumna C = nr zam.
for row in rows[1:]:
if len(row) < 3:
continue # Pomiń wiersze, które nie mają wystarczającej liczby kolumn
link = row[1]
nr_zam = row[2]
if not link:
continue
print(f"\n🔗 Sprawdzam: {link}")
try:
info = mayo.get_order_info(link)
order_number = info["order_number"]
model = info["model"]
print(f"Nr z arkusza: {nr_zam}")
print(f"Nr ze strony: {order_number}")
print(f"Model: {model}")
if normalize(order_number) == normalize(nr_zam):
print("✅ Numer się zgadza")
else:
print("⚠️ Numer NIE pasuje!")
row_data = [
counter,
link,
nr_zam,
model,
get_finish_type(info),
info.get("color_top"),
info.get("color_body"),
info.get("color_neck"),
info.get("color_head"),
info.get("finish_kc"),
info.get("finish_s"),
]
print(f"raw_data: {row_data}")
rows_to_process.append(row_data)
processed_row = process_row(row, mayo, counter)
if processed_row:
rows_to_process.append(processed_row)
counter += 1
except Exception as e:
print(f"❌ Błąd podczas przetwarzania linku {link}: {e}")
# Po zakończeniu pętli, dodaj wszystkie zebrane wiersze za jednym razem
if rows_to_process:
print(f"\n\n--- Podsumowanie ---")