diff --git a/agenda/__init__.py b/agenda/__init__.py index d90359c..7993a6b 100644 --- a/agenda/__init__.py +++ b/agenda/__init__.py @@ -1,5 +1,6 @@ import configparser import json +import operator import os import typing import warnings @@ -96,12 +97,12 @@ def next_uk_fathers_day(input_date: date) -> date: return fathers_day -def get_next_timezone_transition(tz_name: str) -> datetime: +def get_next_timezone_transition(tz_name: str) -> date: """Datetime of the next time the clocks change.""" tz = pytz.timezone(tz_name) dt = next(t for t in tz._utc_transition_times if t > now) - return typing.cast(datetime, dt) + return typing.cast(date, dt.date()) def get_next_bank_holiday() -> dict[str, date | str]: @@ -276,9 +277,8 @@ def get_data() -> dict[str, str | object]: "next_economist": next_economist(today), "bank_holiday": get_next_bank_holiday(), "us_holiday": get_us_holiday(), - "next_uk_general_election": next_uk_general_election, + # "next_uk_general_election": next_uk_general_election, "next_us_presidential_election": next_us_presidential_election, - # "spacex": spacexdata.get_next_spacex_launch(limit=20), "stock_markets": stock_markets(), "uk_clock_change": get_next_timezone_transition("Europe/London"), "us_clock_change": get_next_timezone_transition("America/New_York"), @@ -290,4 +290,24 @@ def get_data() -> dict[str, str | object]: "rockets": thespacedevs.get_launches(rocket_dir, limit=40), } + skip = {"now", "gbpusd", "rockets", "stock_markets", "xmas_last_posting_dates"} + events = [] + for key, value in reply.items(): + if key in skip: + continue + if "holiday" in key: + assert isinstance(value, dict) + event = value + event["name"] = key + else: + event = {"name": key, "date": value} + events.append(event) + + for key, value in xmas_last_posting_dates.items(): + events.append({"name": f"xmas_last_{key}", "date": value}) + + events.sort(key=operator.itemgetter("date")) + + reply["events"] = events + return reply diff --git a/templates/index.html b/templates/index.html index d69f239..c5601a9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,3 +1,5 @@ +{# vim: set ft=htmljinja +#}
@@ -7,6 +9,22 @@ +{% set event_labels = { + "next_economist": "The Economist", + "mothers_day": "Mothers' day", + "fathers_day": "Fathers' day", + "uk_financial_year_end": "End of financial year", + "bank_holiday": "UK bank holiday", + "us_holiday": "US holiday", + "uk_clock_change": "UK clock change", + "us_clock_change": "US clock change", + "next_us_presidential_election": "US pres. election", + "xmas_last_second": "Christmas last posting 2nd class", + "xmas_last_first": "Christmas last posting 1st class", + "xmas_day": "Christmas day", +} +%} ++ {{event.date.strftime("%a, %d, %b %Y")}} + | ++ {{ event_labels[event.name] }} + {%- if "title" in event -%}: {{ event.title }}{% endif %} + | ++ {{ days(event.date) }} + | + {% endfor %} +
{{ market }}
@@ -113,5 +149,7 @@{{ events | pprint }}+ diff --git a/web_view.py b/web_view.py index e2e9da9..dbc812f 100755 --- a/web_view.py +++ b/web_view.py @@ -25,7 +25,7 @@ def index() -> str: return f"{delta.days:>5,d} days {delta.seconds // 3600:>2.0f} hours" def days(when: date) -> str: - return " today" if when == today else f"{(when - today).days:>5,d} days" + return "today" if when == today else f"{(when - today).days:,d} days" return render_template("index.html", days=days, days_hours=days_hours, **data)