diff --git a/justfile b/justfile index 128baf7..030befc 100644 --- a/justfile +++ b/justfile @@ -3,10 +3,10 @@ git_committer_name := "Python EspaƱa" git_committer_email := "contacto@es.python.org" clean-future: - pyevents clean-after -l $(date -I) + pyevents clean-after -v -l $(date -I) fetch-upcoming: - pyevents fetch-upcoming -c communities.toml + pyevents fetch-upcoming -v -c communities.toml commit-events: git fetch diff --git a/src/pyevents/cli.py b/src/pyevents/cli.py index 36ec61e..653e12b 100644 --- a/src/pyevents/cli.py +++ b/src/pyevents/cli.py @@ -38,22 +38,25 @@ def cli(): def clean_after(cutoff_datetime, destination_dirname, verbose): structlog.configure( wrapper_class=structlog.make_filtering_bound_logger( - logging.INFO if verbose else logging.WARNING + logging.DEBUG if verbose else logging.INFO ), ) cutoff_date = cutoff_datetime.date() + logging.debug("Cutoff date set", cutoff_date=cutoff_date) for event_path in Path(destination_dirname).glob("**/*.json"): - logger.debug("Event file found", event_path=event_path) event_date = dt.datetime.strptime( event_path.name.split("_")[0], "%Y-%m-%d" ).date() + logger.debug("Event file found", event_path=event_path, event_date=event_date) if event_date > cutoff_date: logger.info( "Deleting event file", event_path=event_path, event_date=event_date ) event_path.unlink() + else: + logger.info("No event files deleted") @cli.command() @@ -65,7 +68,7 @@ def clean_after(cutoff_datetime, destination_dirname, verbose): def fetch_upcoming(communities_path, destination_dirname, verbose): structlog.configure( wrapper_class=structlog.make_filtering_bound_logger( - logging.INFO if verbose else logging.WARNING + logging.DEBUG if verbose else logging.INFO ), ) @@ -73,19 +76,26 @@ def fetch_upcoming(communities_path, destination_dirname, verbose): communities_data = tomllib.load(f) communities = communities_data["communities"] - upcoming_events = collect_upcoming_events(communities) - if not (destination_dir := Path(destination_dirname)).is_dir(): destination_dir.mkdir() + upcoming_events = collect_upcoming_events(communities) + for community_slug, events in upcoming_events.items(): if not (community_dir := (destination_dir / community_slug)).is_dir(): community_dir.mkdir() for event_data in events: event = event_data["data"]["event"] + logger.debug("Saving new event", event_title=event["title"]) with open(community_dir / f"{event_name_from_data(event)}.json", "w") as fh: json.dump(event, fh, indent=2) + else: + logger.debug( + "No new events found for this community", community_slug=community_slug + ) + else: + logger.info("No new events found") if __name__ == "__main__":