Skip to content

Instantly share code, notes, and snippets.

@hamidazimy
Created September 24, 2024 20:22
from datetime import datetime
import pytz
from astral import Astral
def is_day(city_name="Vancouver"):
city = Astral()[city_name]
now = datetime.now(pytz.timezone(city.timezone))
today = city.sun(date=now.date())
return today['sunrise'] < now < today['sunset']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment