From a37e8ec5c3a8dce4190bd0129a52e39683461d1f Mon Sep 17 00:00:00 2001 From: Kumi Date: Mon, 1 Jul 2024 06:57:16 +0200 Subject: [PATCH] feat: add option to exclude current month data Enhanced `get_transparency_data` to support an `allow_current` flag, preventing the inclusion of data from the current month. This ensures historical data analysis remains consistent when current month data might be incomplete. Updated calls to the function to pass appropriate parameters. --- helpers/finances.py | 13 ++++++++++++- main.py | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/helpers/finances.py b/helpers/finances.py index 001ab35..1d00d60 100644 --- a/helpers/finances.py +++ b/helpers/finances.py @@ -22,13 +22,24 @@ def get_latest_month(data, allow_current=False): return int(latest_month), int(latest_year) -def get_transparency_data(data, year=None, month=None): +def get_transparency_data(data, year=None, month=None, allow_current=False): if year is None: year = max(data.keys()) if month is None: month = max(data[year].keys()) + if ( + not allow_current + and year == str(datetime.now().year) + and month == str(datetime.now().month) + ): + try: + month = max([m for m in data[year].keys() if m != str(datetime.now().month)]) + except ValueError: + year = str(int(year) - 1) + month = max(data[year].keys()) + assert year in data, f"Year {year} not found in data" assert month in data[year], f"Month {month}-{year} not found in data" diff --git a/main.py b/main.py index 3df6e1c..f7cd9bd 100644 --- a/main.py +++ b/main.py @@ -61,7 +61,9 @@ def catch_all(path): finances_period_str = finances_period.strftime("%B %Y") finances_table = generate_transparency_table( - get_transparency_data(finances) + get_transparency_data( + finances, finances_year, finances_month + ) ) kwargs.update(