Refactor get_sheet_data function to improve data fetching and error handling
This commit is contained in:
16
main.py
16
main.py
@@ -126,6 +126,15 @@ def select_sheet(gsheet_api):
|
|||||||
print(f"❌ Błąd podczas pobierania listy arkuszy: {e}")
|
print(f"❌ Błąd podczas pobierania listy arkuszy: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_sheet_data(gsheet_api, sheet_name):
|
||||||
|
"""Fetches all data from a given sheet."""
|
||||||
|
print(f"📋 Pobieram dane z arkusza: {sheet_name}")
|
||||||
|
try:
|
||||||
|
return gsheet_api.get_sheet_data(DOC_NAME, sheet_name)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ Błąd podczas pobierania danych z arkusza: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Inicjalizuj API raz na początku
|
# Inicjalizuj API raz na początku
|
||||||
gsheet_api = GSheetAPI()
|
gsheet_api = GSheetAPI()
|
||||||
@@ -134,11 +143,8 @@ def main():
|
|||||||
if not sheet_name:
|
if not sheet_name:
|
||||||
return
|
return
|
||||||
|
|
||||||
print(f"📋 Pobieram dane z arkusza: {sheet_name}")
|
rows = get_sheet_data(gsheet_api, sheet_name)
|
||||||
try:
|
if rows is None:
|
||||||
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
|
return
|
||||||
|
|
||||||
mayo = MayoSession(MAYO_URL, LOGIN, PASSWORD)
|
mayo = MayoSession(MAYO_URL, LOGIN, PASSWORD)
|
||||||
|
|||||||
Reference in New Issue
Block a user