Fix timezones
This commit is contained in:
parent
7481793dd4
commit
f5120dfbd2
1 changed files with 11 additions and 11 deletions
|
@ -11,7 +11,7 @@ CHANNEL = os.environ["SUNBOT_ANNOUNCE_CHANNEL"]
|
||||||
AUTHORIZATION = "Bearer " + os.environ["SUNBOT_ANNOUNCE_MATTERMOST_TOKEN"]
|
AUTHORIZATION = "Bearer " + os.environ["SUNBOT_ANNOUNCE_MATTERMOST_TOKEN"]
|
||||||
URL = os.environ["SUNBOT_ANNOUNCE_MATTERMOST_API_ENDPOINT"] + "/posts"
|
URL = os.environ["SUNBOT_ANNOUNCE_MATTERMOST_API_ENDPOINT"] + "/posts"
|
||||||
|
|
||||||
GHENT = astral.LocationInfo("Gent", "Belgium", "Europe/Brussels", 51.05, 3.72)
|
LOCATION = astral.LocationInfo("Gent", "Belgium", "Europe/Brussels", 51.05, 3.72)
|
||||||
|
|
||||||
def post(message):
|
def post(message):
|
||||||
payload = {
|
payload = {
|
||||||
|
@ -36,29 +36,29 @@ def wait_until(t, now):
|
||||||
|
|
||||||
def announce_sunrise(today):
|
def announce_sunrise(today):
|
||||||
print("Announcing sunrise", flush=True)
|
print("Announcing sunrise", flush=True)
|
||||||
now = datetime.datetime.now(GHENT.tzinfo)
|
now = LOCATION.tzinfo.localize(datetime.datetime.now())
|
||||||
post(":sunrise: De zon komt op in Gent!\nZonnemiddag om {} (binnen {})\nZonsondergang om {} (binnen {})".format(
|
post(":sunrise: De zon komt op in Gent!\nZonnemiddag om {:%H:%M %Z} (binnen {})\nZonsondergang om {:%H:%M %Z} (binnen {})".format(
|
||||||
tomorrow["noon"],
|
tomorrow["noon"],
|
||||||
format_in(now - tomorrow["noon"]),
|
format_in(tomorrow["noon"] - now),
|
||||||
tomorrow["sunset"],
|
tomorrow["sunset"],
|
||||||
format_in(now - tomorrow["sunset"]),
|
format_in(tomorrow["sunset"] - now),
|
||||||
))
|
))
|
||||||
|
|
||||||
def announce_sunset(tomorrow):
|
def announce_sunset(tomorrow):
|
||||||
print("Announcing sunset", flush=True)
|
print("Announcing sunset", flush=True)
|
||||||
now = datetime.datetime.now(GHENT.tzinfo)
|
now = LOCATION.tzinfo.localize(datetime.datetime.now())
|
||||||
post(":city_sunset: De zon gaat onder in Gent!\nZonsopkomst om {} (binnen {})".format(
|
post(":city_sunset: De zon gaat onder in Gent!\nZonsopkomst om {:%H:%M %Z} (binnen {})".format(
|
||||||
tomorrow["sunrise"],
|
tomorrow["sunrise"],
|
||||||
format_in(now - tomorrow["sunrise"]),
|
format_in(tomorrow["sunrise"] - now),
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("Starting Sunbot", flush=True)
|
print("Starting Sunbot", flush=True)
|
||||||
while True:
|
while True:
|
||||||
today = sun(GHENT.observer, date=datetime.date.today())
|
now = LOCATION.tzinfo.localize(datetime.datetime.now())
|
||||||
tomorrow = sun(GHENT.observer, date=datetime.date.today() + datetime.timedelta(days=1))
|
today = sun(LOCATION.observer, date=now.date())
|
||||||
now = datetime.datetime.now(GHENT.tzinfo)
|
tomorrow = sun(LOCATION.observer, date=now.date() + datetime.timedelta(days=1))
|
||||||
|
|
||||||
if now >= today["sunset"]:
|
if now >= today["sunset"]:
|
||||||
wait_until(tomorrow["sunrise"], now)
|
wait_until(tomorrow["sunrise"], now)
|
||||||
|
|
Loading…
Reference in a new issue