From 6ac998833c0b7ba128af45f970a8c604e7aa0756 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sun, 29 Oct 2023 21:36:57 +0000 Subject: [PATCH] Add sunrise and sunset Closes: #39 --- agenda/__init__.py | 21 +++++++++++++++++++++ templates/index.html | 2 ++ 2 files changed, 23 insertions(+) diff --git a/agenda/__init__.py b/agenda/__init__.py index d6ec273..46bd82d 100644 --- a/agenda/__init__.py +++ b/agenda/__init__.py @@ -13,6 +13,7 @@ from typing import List import dateutil import dateutil.parser import dateutil.tz +import ephem import exchange_calendars import holidays import lxml @@ -593,6 +594,22 @@ def waste_collection_events() -> list[Event]: return events +def bristol(): + observer = ephem.Observer() + observer.lat, observer.lon = "51.4545", "-2.5879" + return observer + + +def sunrise(observer): + """Sunrise.""" + return observer.next_rising(ephem.Sun(observer)).datetime() + + +def sunset(observer): + """Sunrise.""" + return observer.next_setting(ephem.Sun(observer)).datetime() + + def get_data(now: datetime) -> typing.Mapping[str, str | object]: """Get data to display on agenda dashboard.""" rocket_dir = os.path.join(data_dir, "thespacedevs") @@ -634,6 +651,10 @@ def get_data(now: datetime) -> typing.Mapping[str, str | object]: event = Event(name=key, date=value) events.append(event) + observer = bristol() + reply["sunrise"] = sunrise(observer) + reply["sunset"] = sunset(observer) + for key, value in xmas_last_posting_dates.items(): events.append(Event(name=f"xmas_last_{key}", date=value)) diff --git a/templates/index.html b/templates/index.html index 33ebeb6..9755093 100644 --- a/templates/index.html +++ b/templates/index.html @@ -55,6 +55,8 @@ unknown {% endif %} +
  • Sunrise: {{ sunrise.strftime("%H:%M:%S") }} / + Sunset: {{ sunset.strftime("%H:%M:%S") }}