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(