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():
gsheet_api = GSheetAPI()
sheet_name = select_sheet(gsheet_api)
sheet_name = select_sheet()
if not sheet_name:
return

View File

@@ -1,19 +1,12 @@
import datetime
from config import DOC_NAME, RESULT_DOC
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 None
def select_sheet():
"""Generates the sheet name based on the current month and year (MM.YYYY)."""
now = datetime.datetime.now()
sheet_name = now.strftime("%m.%Y")
print(f"📄 Automatycznie wybrano arkusz: {sheet_name}")
return sheet_name
def get_sheet_data(gsheet_api, sheet_name):
"""Fetches all data from a given sheet."""