Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate statistics #47

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion festivus.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def generate_calendars():
f'<li><a href="{url}">{calendar.location[2]}</a> {calendar.location[1]}, {calendar.location[0]} {calendar.years()}</li>'
)
prev_last_year = last_year
f.write("</ul></li></ul></body>")
f.write('</ul></li></ul><p><a href="stats.csv">Statistics</a></body>')


class Calendar:
Expand Down
66 changes: 66 additions & 0 deletions stats.py
Original file line number Diff line number Diff line change
@@ -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)))
Loading