Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed updsuntimes.py to work with Astral 2 #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions automathemely/autoth_tools/updsuntimes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/env python3
import logging
from datetime import timedelta
from datetime import date
from time import sleep

import pytz
import tzlocal
from astral import Location
from astral import LocationInfo
from astral.sun import sun

from automathemely.autoth_tools.utils import get_local, verify_desktop_session

Expand Down Expand Up @@ -63,7 +65,7 @@ def main(us_se):
loc = us_se['location']['manual']

try:
location = Location()
location = LocationInfo()
location.name = loc['city']
location.region = loc['region']
location.latitude = loc['latitude']
Expand All @@ -72,9 +74,10 @@ def main(us_se):
except ValueError as e:
logger.error(str(e))
return

sunrise = location.sun()['sunrise'].replace(second=0) + timedelta(minutes=us_se['offset']['sunrise'])
sunset = location.sun()['sunset'].replace(second=0) + timedelta(minutes=us_se['offset']['sunset'])

s = sun(location.observer, date=date.today(), tzinfo=pytz.timezone(location.timezone))
sunrise = s['sunrise'].replace(second=0) + timedelta(minutes=us_se['offset']['sunrise'])
sunset = s['sunset'].replace(second=0) + timedelta(minutes=us_se['offset']['sunset'])

# Convert to UTC for storage
return sunrise.astimezone(pytz.utc), sunset.astimezone(pytz.utc)
Expand Down