Refactor select_sheet function to automatically generate sheet names based on the current month and year

This commit is contained in:
2025-10-29 21:46:26 +01:00
parent 3f1fd7e942
commit f5abf68bb6
3 changed files with 8 additions and 15 deletions

View File

@@ -7,7 +7,7 @@ from processing import process_all_rows
def main(): def main():
gsheet_api = GSheetAPI() gsheet_api = GSheetAPI()
sheet_name = select_sheet(gsheet_api) sheet_name = select_sheet()
if not sheet_name: if not sheet_name:
return return

View File

@@ -1,20 +1,13 @@
import datetime
from config import DOC_NAME, RESULT_DOC from config import DOC_NAME, RESULT_DOC
def select_sheet(gsheet_api): def select_sheet():
"""Lists available sheets and prompts the user to select one.""" """Generates the sheet name based on the current month and year (MM.YYYY)."""
print("📄 Pobieram listę arkuszy...") now = datetime.datetime.now()
try: sheet_name = now.strftime("%m.%Y")
sheets = gsheet_api.list_sheets(DOC_NAME) print(f"📄 Automatycznie wybrano arkusz: {sheet_name}")
for i, name in enumerate(sheets):
print(f"{i+1}. {name}")
sheet_name = input("\nWybierz arkusz do przetworzenia: ")
return sheet_name return sheet_name
except Exception as e:
print(f"❌ Błąd podczas pobierania listy arkuszy: {e}")
return None
def get_sheet_data(gsheet_api, sheet_name): def get_sheet_data(gsheet_api, sheet_name):
"""Fetches all data from a given sheet.""" """Fetches all data from a given sheet."""
print(f"📋 Pobieram dane z arkusza: {sheet_name}") print(f"📋 Pobieram dane z arkusza: {sheet_name}")