From 3acad3649d330fa74c0e7dd9dbde25a612646013 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 1 Nov 2023 17:29:47 +0000 Subject: [PATCH] Add event colours to calendar Closes: #42 --- agenda/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/agenda/__init__.py b/agenda/__init__.py index 62bff02..e5ee290 100644 --- a/agenda/__init__.py +++ b/agenda/__init__.py @@ -56,6 +56,23 @@ config.read(config_filename) access_key = config.get("exchangerate", "access_key") data_dir = config.get("data", "dir") +colors = { + "primary-subtle": "#cfe2ff", + "secondary-subtle": "#e2e3e5", + "success-subtle": "#d1e7dd", + "info-subtle": "#cff4fc", + "warning-subtle": "#fff3cd", + "danger-subtle": "#f8d7da", +} + +event_type_color_map = { + "bank_holiday": "success-subtle", + "conference": "primary-subtle", + "us_holiday": "secondary-subtle", + "birthday": "info-subtle", + "waste_schedule": "danger-subtle", +} + def extract_weekday_date(html: str) -> date | None: """Furthest date of GWR advance ticket booking.""" @@ -651,6 +668,9 @@ def build_events_for_calendar(events: list[Event]) -> list[dict[str, typing.Any] "start": e.date.isoformat(), "end": end.isoformat(), } + if e.name in event_type_color_map: + item["color"] = colors[event_type_color_map[e.name]] + item["textColor"] = "black" if e.url: item["url"] = e.url items.append(item)