Add sunrise and sunset

Closes: #39
This commit is contained in:
Edward Betts 2023-10-29 21:36:57 +00:00
parent 9a79573e16
commit 6ac998833c
2 changed files with 23 additions and 0 deletions

View file

@ -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))

View file

@ -55,6 +55,8 @@
unknown
{% endif %}
</li>
<li>Sunrise: {{ sunrise.strftime("%H:%M:%S") }} /
Sunset: {{ sunset.strftime("%H:%M:%S") }}</li>
</ul>
<table class="table table-hover w-auto">