@@ -38,22 +38,25 @@ def cli():
3838def clean_after (cutoff_datetime , destination_dirname , verbose ):
3939 structlog .configure (
4040 wrapper_class = structlog .make_filtering_bound_logger (
41- logging .INFO if verbose else logging .WARNING
41+ logging .DEBUG if verbose else logging .INFO
4242 ),
4343 )
4444
4545 cutoff_date = cutoff_datetime .date ()
46+ logging .debug ("Cutoff date set" , cutoff_date = cutoff_date )
4647
4748 for event_path in Path (destination_dirname ).glob ("**/*.json" ):
48- logger .debug ("Event file found" , event_path = event_path )
4949 event_date = dt .datetime .strptime (
5050 event_path .name .split ("_" )[0 ], "%Y-%m-%d"
5151 ).date ()
52+ logger .debug ("Event file found" , event_path = event_path , event_date = event_date )
5253 if event_date > cutoff_date :
5354 logger .info (
5455 "Deleting event file" , event_path = event_path , event_date = event_date
5556 )
5657 event_path .unlink ()
58+ else :
59+ logger .info ("No event files deleted" )
5760
5861
5962@cli .command ()
@@ -65,27 +68,34 @@ def clean_after(cutoff_datetime, destination_dirname, verbose):
6568def fetch_upcoming (communities_path , destination_dirname , verbose ):
6669 structlog .configure (
6770 wrapper_class = structlog .make_filtering_bound_logger (
68- logging .INFO if verbose else logging .WARNING
71+ logging .DEBUG if verbose else logging .INFO
6972 ),
7073 )
7174
7275 with open (communities_path , "rb" ) as f :
7376 communities_data = tomllib .load (f )
7477 communities = communities_data ["communities" ]
7578
76- upcoming_events = collect_upcoming_events (communities )
77-
7879 if not (destination_dir := Path (destination_dirname )).is_dir ():
7980 destination_dir .mkdir ()
8081
82+ upcoming_events = collect_upcoming_events (communities )
83+
8184 for community_slug , events in upcoming_events .items ():
8285 if not (community_dir := (destination_dir / community_slug )).is_dir ():
8386 community_dir .mkdir ()
8487
8588 for event_data in events :
8689 event = event_data ["data" ]["event" ]
90+ logger .debug ("Saving new event" , event_title = event ["title" ])
8791 with open (community_dir / f"{ event_name_from_data (event )} .json" , "w" ) as fh :
8892 json .dump (event , fh , indent = 2 )
93+ else :
94+ logger .debug (
95+ "No new events found for this community" , community_slug = community_slug
96+ )
97+ else :
98+ logger .info ("No new events found" )
8999
90100
91101if __name__ == "__main__" :
0 commit comments