diff --git a/src/cli.py b/src/cli.py index 429d5e1..55fbea3 100755 --- a/src/cli.py +++ b/src/cli.py @@ -556,36 +556,6 @@ def main(): print( f"'Jednotný kurz' pro daňové účely podle metodiky ČNB pro {currency_code} za rok {year} nebyl nalezen." ) - debug_print("HIT: Validation condition") - print("VALIDATION: Condition matched!") - # Validation command - base_threshold = args.change_threshold - adaptive = not args.no_adaptive - - if args.currency: - # Validate specific currency - debug_print(f"Validuji data pro měnu {args.currency}...") - results = data_validator.validate_currency_data( - args.currency, args.year, base_threshold, adaptive - ) - - if args.json: - output_json(results) - else: - text_output = data_validator.format_validation_text(results) - print(text_output) - else: - # Validate all currencies - debug_print("Validuji data pro všechny měny...") - results = data_validator.validate_all_currencies( - args.year, base_threshold, adaptive - ) - - if args.json: - output_json(results) - else: - text_output = data_validator.format_validation_text(results) - print(text_output) elif args.currency and not args.get_rate: # Pokud je zadána měna, ale není zadán --get-rate, vytiskneme poslední dostupný kurz # Toto musí být až po --stats, jinak by se --stats nikdy nevykonalo diff --git a/src/rate_reporter.py b/src/rate_reporter.py index 4d86da6..ba5254c 100644 --- a/src/rate_reporter.py +++ b/src/rate_reporter.py @@ -224,6 +224,35 @@ def _is_year_complete_for_tax_calculation(year): return True +def _auto_download_missing_monthly_data(year, currency_code, output_dir="data"): + """ + Automatically download missing monthly data for tax calculation (silent operation). + + :param year: Year to check + :param currency_code: Currency code + :param output_dir: Output directory + """ + missing_months = get_missing_months_for_tax_calculation(year, currency_code) + if missing_months: + debug_print( + f"Auto-downloading missing monthly data for {currency_code} {year}: months {', '.join(f'{m:02d}' for m in missing_months)}" + ) + for month in missing_months: + start_date = f"01.{month:02d}.{year}" + last_day = calendar.monthrange(year, month)[1] + end_date = f"{last_day:02d}.{month:02d}.{year}" + try: + data_fetcher.download_monthly_data( + currency_code, start_date, end_date, output_dir=output_dir + ) + # Small delay to be respectful to the API + time.sleep(0.5) + except Exception as e: + debug_print( + f"Failed to download data for {currency_code} {month:02d}/{year}: {e}" + ) + + def calculate_tax_yearly_average(year, currency_code, output_dir="data"): """ Vypočítá 'Jednotný kurz' pro daňové účely podle metodiky ČNB. @@ -238,31 +267,8 @@ def calculate_tax_yearly_average(year, currency_code, output_dir="data"): f"Vypočítávám 'Jednotný kurz' pro daňové účely podle metodiky ČNB pro {currency_code} za rok {year}..." ) - # Zkusíme stáhnout chybějící měsíční data - missing_months = get_missing_months_for_tax_calculation(year, currency_code) - if missing_months: - debug_print( - f"Nalezeny chybějící měsíce pro rok {year}: {', '.join(f'{m:02d}' for m in missing_months)}. Stahuji měsíční data..." - ) - for month in missing_months: - start_date = f"01.{month:02d}.{year}" - last_day = calendar.monthrange(year, month)[1] - end_date = f"{last_day:02d}.{month:02d}.{year}" - debug_print( - f"Stahuji měsíční data pro {currency_code} za {month:02d}/{year}..." - ) - data_fetcher.download_monthly_data( - currency_code, start_date, end_date, output_dir="data" - ) - # Přidáme zpoždění, abychom nezatěžovali API - time.sleep(1) - - # Zkontrolujeme, zda je rok kompletní po stažení dat - if not _is_year_complete_for_tax_calculation(year): - debug_print( - f"Rok {year} není kompletní pro výpočet 'Jednotného kurzu'. Všechny měsíce musí mít dostupné kurzy k posledním dnům." - ) - return None + # Auto-download missing monthly data if needed (silent operation) + _auto_download_missing_monthly_data(year, currency_code, output_dir) # Zkontrolujeme, zda databáze obsahuje data pro daný rok if not rate_finder.check_year_data_in_db(year):