Skip to content

Instantly share code, notes, and snippets.

@hamidazimy
Created September 24, 2024 20:22
Show Gist options
  • Save hamidazimy/628a515a653c78f8365cd7894385e5e0 to your computer and use it in GitHub Desktop.
Save hamidazimy/628a515a653c78f8365cd7894385e5e0 to your computer and use it in GitHub Desktop.
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