From 5f00e63f71a9c7056f15e8e83b17eaeea8755088 Mon Sep 17 00:00:00 2001 From: bartool Date: Wed, 29 Oct 2025 21:31:09 +0100 Subject: [PATCH] Refactor main function to improve sheet selection process and error handling --- main.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 954d58a..69256a0 100644 --- a/main.py +++ b/main.py @@ -111,20 +111,28 @@ def process_row(row, mayo, counter): print(f"❌ Błąd podczas przetwarzania linku {link}: {e}") return None -def main(): - # Inicjalizuj API raz na początku - gsheet_api = GSheetAPI() - +def select_sheet(gsheet_api): + """Lists available sheets and prompts the user to select one.""" print("📄 Pobieram listę arkuszy...") try: sheets = gsheet_api.list_sheets(DOC_NAME) for i, name in enumerate(sheets): print(f"{i+1}. {name}") + + sheet_name = input("\nWybierz arkusz do przetworzenia: ") + return sheet_name + except Exception as e: print(f"❌ Błąd podczas pobierania listy arkuszy: {e}") - return + return None - sheet_name = input("\nWybierz arkusz do przetworzenia: ") +def main(): + # Inicjalizuj API raz na początku + gsheet_api = GSheetAPI() + + sheet_name = select_sheet(gsheet_api) + if not sheet_name: + return print(f"📋 Pobieram dane z arkusza: {sheet_name}") try: