Skip to content

Commit 150aa92

Browse files
authored
Merge pull request #1370 from caternuson/magtag_weather_update
Update MagTag_Weather code
2 parents 169c825 + beaebed commit 150aa92

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

MagTag_Weather/magtag_weather.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def get_forecast(location):
7575
"""Use OneCall API to fetch forecast and timezone data."""
7676
resp = magtag.network.fetch(get_data_source_url(api="onecall", location=location))
7777
json_data = resp.json()
78-
return json_data["daily"], json_data["timezone_offset"]
78+
return json_data["daily"], json_data["current"]["dt"], json_data["timezone_offset"]
7979

8080

8181
def make_banner(x=0, y=0):
@@ -150,10 +150,10 @@ def update_today(data, tz_offset=0):
150150
today_sunset.text = "{:2d}:{:02d} PM".format(sunset.tm_hour - 12, sunset.tm_min)
151151

152152

153-
def go_to_sleep():
153+
def go_to_sleep(current_time):
154154
"""Enter deep sleep for time needed."""
155155
# compute current time offset in seconds
156-
hour, minutes, seconds = time.localtime()[3:6]
156+
hour, minutes, seconds = time.localtime(current_time)[3:6]
157157
seconds_since_midnight = 60 * (hour * 60 + minutes) + seconds
158158
# wake up 15 minutes after midnite
159159
seconds_to_sleep = (24 * 60 * 60 - seconds_since_midnight) + 15 * 60
@@ -172,6 +172,12 @@ def go_to_sleep():
172172
today_date.anchor_point = (0, 0)
173173
today_date.anchored_position = (15, 13)
174174

175+
city_name = label.Label(
176+
terminalio.FONT, text=secrets["openweather_location"], color=0x000000
177+
)
178+
city_name.anchor_point = (0, 0)
179+
city_name.anchored_position = (15, 24)
180+
175181
today_icon = displayio.TileGrid(
176182
icons_large_bmp,
177183
pixel_shader=icons_small_pal,
@@ -213,6 +219,7 @@ def go_to_sleep():
213219

214220
today_banner = displayio.Group(max_size=10)
215221
today_banner.append(today_date)
222+
today_banner.append(city_name)
216223
today_banner.append(today_icon)
217224
today_banner.append(today_morn_temp)
218225
today_banner.append(today_day_temp)
@@ -230,29 +237,20 @@ def go_to_sleep():
230237
make_banner(x=210, y=102),
231238
]
232239

233-
city_name = label.Label(
234-
terminalio.FONT, text=secrets["openweather_location"], color=0x000000
235-
)
236-
city_name.anchor_point = (0, 0)
237-
city_name.anchored_position = (15, 24)
238-
239240
magtag.splash.append(today_banner)
240241
for future_banner in future_banners:
241242
magtag.splash.append(future_banner)
242-
magtag.splash.append(city_name)
243243

244244
# ===========
245245
# M A I N
246246
# ===========
247-
magtag.get_local_time()
248-
249247
print("Getting Lat/Lon...")
250248
latlon = get_latlon()
251249
print(secrets["openweather_location"])
252250
print(latlon)
253251

254252
print("Fetching forecast...")
255-
forecast_data, local_tz_offset = get_forecast(latlon)
253+
forecast_data, utc_time, local_tz_offset = get_forecast(latlon)
256254

257255
print("Updating...")
258256
update_today(forecast_data[0], local_tz_offset)
@@ -265,6 +263,7 @@ def go_to_sleep():
265263
time.sleep(magtag.display.time_to_refresh + 1)
266264

267265
print("Sleeping...")
268-
go_to_sleep()
266+
go_to_sleep(utc_time + local_tz_offset)
269267
# entire code will run again after deep sleep cycle
270268
# similar to hitting the reset button
269+

0 commit comments

Comments
 (0)