Skip to content

Commit

Permalink
Cleanup future events
Browse files Browse the repository at this point in the history
Fix gh-18.
  • Loading branch information
astrojuanlu committed May 16, 2023
1 parent 723201b commit 72375b6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ jobs:
run: pip install -r requirements.txt
# - name: Clone events directory
# run: mkdir events && cd events && cp -r ../.git . && git pull && git checkout events && cd ..
- name: Run main.py
- name: Cleanup future events
run: pyevents clean-after -l $(date -I)
- name: Fetch upcoming events
run: pyevents fetch-upcoming -c communities.toml
env: # Set the secret as an input
MEETUP_CLIENT_KEY: ${{ secrets.MEETUP_CLIENT_KEY }}
Expand Down
32 changes: 32 additions & 0 deletions src/pyevents/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime as dt
import json
import logging
import tomllib
Expand All @@ -24,6 +25,37 @@ def cli():
pass


@cli.command()
@click.option(
"--cutoff-date",
"-l",
"cutoff_datetime",
type=click.DateTime(["%Y-%m-%d"]),
default=dt.date.today().strftime("%Y-%m-%d"),
)
@click.option("--destination-dirname", "-d", type=click.Path(), default="_events")
@click.option("--verbose", "-v", is_flag=True)
def clean_after(cutoff_datetime, destination_dirname, verbose):
structlog.configure(
wrapper_class=structlog.make_filtering_bound_logger(
logging.INFO if verbose else logging.WARNING
),
)

cutoff_date = cutoff_datetime.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()
if event_date > cutoff_date:
logger.info(
"Deleting event file", event_path=event_path, event_date=event_date
)
event_path.unlink()


@cli.command()
@click.option(
"--communities", "-c", "communities_path", type=click.Path(), required=True
Expand Down

0 comments on commit 72375b6

Please sign in to comment.