Refactor main function to improve sheet selection process and error handling
This commit is contained in:
22
main.py
22
main.py
@@ -111,20 +111,28 @@ def process_row(row, mayo, counter):
|
|||||||
print(f"❌ Błąd podczas przetwarzania linku {link}: {e}")
|
print(f"❌ Błąd podczas przetwarzania linku {link}: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def main():
|
def select_sheet(gsheet_api):
|
||||||
# Inicjalizuj API raz na początku
|
"""Lists available sheets and prompts the user to select one."""
|
||||||
gsheet_api = GSheetAPI()
|
|
||||||
|
|
||||||
print("📄 Pobieram listę arkuszy...")
|
print("📄 Pobieram listę arkuszy...")
|
||||||
try:
|
try:
|
||||||
sheets = gsheet_api.list_sheets(DOC_NAME)
|
sheets = gsheet_api.list_sheets(DOC_NAME)
|
||||||
for i, name in enumerate(sheets):
|
for i, name in enumerate(sheets):
|
||||||
print(f"{i+1}. {name}")
|
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: ")
|
sheet_name = input("\nWybierz arkusz do przetworzenia: ")
|
||||||
|
return sheet_name
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ Błąd podczas pobierania listy arkuszy: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
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}")
|
print(f"📋 Pobieram dane z arkusza: {sheet_name}")
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user