@@ -75,7 +75,7 @@ def get_forecast(location):
75
75
"""Use OneCall API to fetch forecast and timezone data."""
76
76
resp = magtag .network .fetch (get_data_source_url (api = "onecall" , location = location ))
77
77
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" ]
79
79
80
80
81
81
def make_banner (x = 0 , y = 0 ):
@@ -150,10 +150,10 @@ def update_today(data, tz_offset=0):
150
150
today_sunset .text = "{:2d}:{:02d} PM" .format (sunset .tm_hour - 12 , sunset .tm_min )
151
151
152
152
153
- def go_to_sleep ():
153
+ def go_to_sleep (current_time ):
154
154
"""Enter deep sleep for time needed."""
155
155
# compute current time offset in seconds
156
- hour , minutes , seconds = time .localtime ()[3 :6 ]
156
+ hour , minutes , seconds = time .localtime (current_time )[3 :6 ]
157
157
seconds_since_midnight = 60 * (hour * 60 + minutes ) + seconds
158
158
# wake up 15 minutes after midnite
159
159
seconds_to_sleep = (24 * 60 * 60 - seconds_since_midnight ) + 15 * 60
@@ -172,6 +172,12 @@ def go_to_sleep():
172
172
today_date .anchor_point = (0 , 0 )
173
173
today_date .anchored_position = (15 , 13 )
174
174
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
+
175
181
today_icon = displayio .TileGrid (
176
182
icons_large_bmp ,
177
183
pixel_shader = icons_small_pal ,
@@ -213,6 +219,7 @@ def go_to_sleep():
213
219
214
220
today_banner = displayio .Group (max_size = 10 )
215
221
today_banner .append (today_date )
222
+ today_banner .append (city_name )
216
223
today_banner .append (today_icon )
217
224
today_banner .append (today_morn_temp )
218
225
today_banner .append (today_day_temp )
@@ -230,29 +237,20 @@ def go_to_sleep():
230
237
make_banner (x = 210 , y = 102 ),
231
238
]
232
239
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
-
239
240
magtag .splash .append (today_banner )
240
241
for future_banner in future_banners :
241
242
magtag .splash .append (future_banner )
242
- magtag .splash .append (city_name )
243
243
244
244
# ===========
245
245
# M A I N
246
246
# ===========
247
- magtag .get_local_time ()
248
-
249
247
print ("Getting Lat/Lon..." )
250
248
latlon = get_latlon ()
251
249
print (secrets ["openweather_location" ])
252
250
print (latlon )
253
251
254
252
print ("Fetching forecast..." )
255
- forecast_data , local_tz_offset = get_forecast (latlon )
253
+ forecast_data , utc_time , local_tz_offset = get_forecast (latlon )
256
254
257
255
print ("Updating..." )
258
256
update_today (forecast_data [0 ], local_tz_offset )
@@ -265,6 +263,7 @@ def go_to_sleep():
265
263
time .sleep (magtag .display .time_to_refresh + 1 )
266
264
267
265
print ("Sleeping..." )
268
- go_to_sleep ()
266
+ go_to_sleep (utc_time + local_tz_offset )
269
267
# entire code will run again after deep sleep cycle
270
268
# similar to hitting the reset button
269
+
0 commit comments