From 9466bd05d5c8542c4e11cae78d9f530b148d8099 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 9 Nov 2024 12:51:35 +0100 Subject: [PATCH] Generate statistics --- .github/workflows/publish.yml | 6 ++++ festivus.py | 2 +- stats.py | 66 +++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 stats.py diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6a7b324..49eb04e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -20,6 +20,12 @@ jobs: - name: Check flake8 run: | poetry run flake8 + - name: Create generated directory + run: | + mkdir -p generated + - name: Generate stats + run: | + python3 stats.py >generated/stats.csv - name: Generate run: | poetry run python festivus.py diff --git a/festivus.py b/festivus.py index 39ccfb7..2d2ec0c 100644 --- a/festivus.py +++ b/festivus.py @@ -59,7 +59,7 @@ def generate_calendars(): f'
  • {calendar.location[2]} {calendar.location[1]}, {calendar.location[0]} {calendar.years()}
  • ' ) prev_last_year = last_year - f.write("") + f.write('

    Statistics') class Calendar: diff --git a/stats.py b/stats.py new file mode 100644 index 0000000..41b26f6 --- /dev/null +++ b/stats.py @@ -0,0 +1,66 @@ +import datetime +import pathlib + + +WEEKDAYS = ( + "monday", + "tuesday", + "wednesday", + "thursday", + "friday", + "saturday", + "sunday", +) +KINDS = { + "(Estatal)": "Spain", + "(Local)": "City", + "(Autonómica)": "Autonomous region", + "(Autonòmica)": "Autonomous region", +} + +print( + "\t".join( + ( + "country", + "autonomous_community", + "city", + "year", + "month", + "day", + "weekday number", + "weekday name", + "date", + "kind", + "name", + ) + ) +) + + +for f in pathlib.Path(".").glob("*/*/*/*/*.cal"): + if str(f) in ( + "data/España/Comunitat Valenciana/Paterna/2022.cal", + "data/España/Comunitat Valenciana/Burjassot/2022.cal", + ): + continue + for line in f.read_text().splitlines(): + if line.startswith("#"): + continue + date, rest = line.split(" ", 1) + name, kind = rest.rsplit(" ", 1) + date = datetime.date.fromisoformat(date) + _, country, autonomous_community, city, _ = f.parts + row = ( + country, + autonomous_community, + city, + date.year, + date.month, + date.day, + date.weekday(), + WEEKDAYS[date.weekday()], + date.isoformat(), + KINDS[kind], + name, + ) + print("\t".join(map(str, row)))