agenda/agenda/sun.py

24 lines
581 B
Python

"""Sunrise and sunset times."""
import typing
from datetime import datetime
import ephem
def bristol() -> ephem.Observer:
"""Location of Bristol."""
observer = ephem.Observer()
observer.lat, observer.lon = "51.4545", "-2.5879"
return observer
def sunrise(observer: ephem.Observer) -> datetime:
"""Sunrise."""
return typing.cast(datetime, observer.next_rising(ephem.Sun(observer)).datetime())
def sunset(observer: ephem.Observer) -> datetime:
"""Sunrise."""
return typing.cast(datetime, observer.next_setting(ephem.Sun(observer)).datetime())