Refactor process_row function to streamline row processing and error handling
This commit is contained in:
73
main.py
73
main.py
@@ -65,43 +65,16 @@ def get_finish_type(row_data):
|
||||
|
||||
return None
|
||||
|
||||
def main():
|
||||
# Inicjalizuj API raz na początku
|
||||
gsheet_api = GSheetAPI()
|
||||
|
||||
print("📄 Pobieram listę arkuszy...")
|
||||
try:
|
||||
sheets = gsheet_api.list_sheets(DOC_NAME)
|
||||
for i, name in enumerate(sheets):
|
||||
print(f"{i+1}. {name}")
|
||||
except Exception as e:
|
||||
print(f"❌ Błąd podczas pobierania listy arkuszy: {e}")
|
||||
return
|
||||
|
||||
sheet_name = input("\nWybierz arkusz do przetworzenia: ")
|
||||
|
||||
print(f"📋 Pobieram dane z arkusza: {sheet_name}")
|
||||
try:
|
||||
rows = gsheet_api.get_sheet_data(DOC_NAME, sheet_name)
|
||||
except Exception as e:
|
||||
print(f"❌ Błąd podczas pobierania danych z arkusza: {e}")
|
||||
return
|
||||
|
||||
mayo = MayoSession(MAYO_URL, LOGIN, PASSWORD)
|
||||
mayo.login()
|
||||
|
||||
rows_to_process = []
|
||||
counter = 1
|
||||
# Zakładamy: kolumna B = link, kolumna C = nr zam.
|
||||
for row in rows[1:]:
|
||||
def process_row(row, mayo, counter):
|
||||
"""Processes a single row from the sheet."""
|
||||
if len(row) < 3:
|
||||
continue # Pomiń wiersze, które nie mają wystarczającej liczby kolumn
|
||||
return None # Skip rows with insufficient columns
|
||||
|
||||
link = row[1]
|
||||
nr_zam = row[2]
|
||||
|
||||
if not link:
|
||||
continue
|
||||
return None
|
||||
|
||||
print(f"\n🔗 Sprawdzam: {link}")
|
||||
try:
|
||||
@@ -132,11 +105,45 @@ def main():
|
||||
info.get("finish_s"),
|
||||
]
|
||||
print(f"raw_data: {row_data}")
|
||||
rows_to_process.append(row_data)
|
||||
counter += 1
|
||||
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()
|
||||
|
||||
print("📄 Pobieram listę arkuszy...")
|
||||
try:
|
||||
sheets = gsheet_api.list_sheets(DOC_NAME)
|
||||
for i, name in enumerate(sheets):
|
||||
print(f"{i+1}. {name}")
|
||||
except Exception as e:
|
||||
print(f"❌ Błąd podczas pobierania listy arkuszy: {e}")
|
||||
return
|
||||
|
||||
sheet_name = input("\nWybierz arkusz do przetworzenia: ")
|
||||
|
||||
print(f"📋 Pobieram dane z arkusza: {sheet_name}")
|
||||
try:
|
||||
rows = gsheet_api.get_sheet_data(DOC_NAME, sheet_name)
|
||||
except Exception as e:
|
||||
print(f"❌ Błąd podczas pobierania danych z arkusza: {e}")
|
||||
return
|
||||
|
||||
mayo = MayoSession(MAYO_URL, LOGIN, PASSWORD)
|
||||
mayo.login()
|
||||
|
||||
rows_to_process = []
|
||||
counter = 1
|
||||
# Zakładamy: kolumna B = link, kolumna C = nr zam.
|
||||
for row in rows[1:]:
|
||||
processed_row = process_row(row, mayo, counter)
|
||||
if processed_row:
|
||||
rows_to_process.append(processed_row)
|
||||
counter += 1
|
||||
|
||||
# Po zakończeniu pętli, dodaj wszystkie zebrane wiersze za jednym razem
|
||||
if rows_to_process:
|
||||
|
||||
Reference in New Issue
Block a user