import datetime import logging from tadas.snowflake import facts_source from tadas.platform import config logger = logging.getLogger(__name__) def find_common_max_value(lists: list): common = set(lists[0]).intersection(*lists[1:]) max_common = max(common) if common else None logger.info(f'{max_common=}') return max_common def find_latest_available_date(dsps) -> datetime.date: available_dates = facts_source.load_available_dates( dsps=dsps, max_days_back=config.get('DAYS_BACK') ) logger.info(f"{available_dates=}") latest_available_date = find_common_max_value( lists=list(available_dates.values())) logger.info(f"{latest_available_date=}") if not latest_available_date: raise ValueError(f'No common available dates found in {available_dates}') return latest_available_date