Skip to content

Commit ca15488

Browse files
authored
Merge pull request #26 from python-spain/improve-logging
Improve logging
2 parents 4413234 + 6924997 commit ca15488

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ git_committer_name := "Python España"
33
git_committer_email := "contacto@es.python.org"
44

55
clean-future:
6-
pyevents clean-after -l $(date -I)
6+
pyevents clean-after -v -l $(date -I)
77

88
fetch-upcoming:
9-
pyevents fetch-upcoming -c communities.toml
9+
pyevents fetch-upcoming -v -c communities.toml
1010

1111
commit-events:
1212
git fetch

src/pyevents/cli.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,25 @@ def cli():
3838
def 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):
6568
def 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

91101
if __name__ == "__main__":

0 commit comments

Comments
 (0)