11
11
from adafruit_magtag .magtag import MagTag
12
12
13
13
# --| USER CONFIG |--------------------------
14
- LAT = 47.6 # latitude
15
- LON = - 122.3 # longitude
16
- TMZ = "America/Los_Angeles" # https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
17
- METRIC = False # set to True for metric units
18
- CITY = None # optional
14
+ LAT = 47.6 # latitude
15
+ LON = - 122.3 # longitude
16
+ TMZ = "America/Los_Angeles" # https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
17
+ METRIC = False # set to True for metric units
18
+ CITY = None # optional
19
19
# -------------------------------------------
20
20
21
21
# ----------------------------
58
58
59
59
# Map the above WMO codes to index of icon in 3x3 spritesheet
60
60
WMO_CODE_TO_ICON = (
61
- (0 ,), # 0 = sunny
62
- (1 ,), # 1 = partly sunny/cloudy
63
- (2 ,), # 2 = cloudy
64
- (3 ,), # 3 = very cloudy
65
- (61 , 63 , 65 ), # 4 = rain
66
- (51 , 53 , 55 , 80 , 81 , 82 ), # 5 = showers
67
- (95 , 96 , 99 ), # 6 = storms
68
- (56 , 57 , 66 , 67 , 71 , 73 , 75 , 77 , 85 , 86 ), # 7 = snow
69
- (45 , 48 ), # 8 = fog and stuff
61
+ (0 ,), # 0 = sunny
62
+ (1 ,), # 1 = partly sunny/cloudy
63
+ (2 ,), # 2 = cloudy
64
+ (3 ,), # 3 = very cloudy
65
+ (61 , 63 , 65 ), # 4 = rain
66
+ (51 , 53 , 55 , 80 , 81 , 82 ), # 5 = showers
67
+ (95 , 96 , 99 ), # 6 = storms
68
+ (56 , 57 , 66 , 67 , 71 , 73 , 75 , 77 , 85 , 86 ), # 7 = snow
69
+ (45 , 48 ), # 8 = fog and stuff
70
70
)
71
71
72
72
magtag = MagTag ()
85
85
# /////////////////////////////////////////////////////////////////////////
86
86
# helper functions
87
87
88
+
88
89
def get_forecast ():
89
- URL = f"https://api.open-meteo.com/v1/forecast?latitude={ LAT } &longitude={ LON } &"
90
+ URL = f"https://api.open-meteo.com/v1/forecast?latitude={ LAT } &longitude={ LON } &"
90
91
URL += "daily=weather_code,temperature_2m_max,temperature_2m_min"
91
92
URL += ",sunrise,sunset,wind_speed_10m_max,wind_direction_10m_dominant"
92
93
URL += "&timeformat=unixtime"
@@ -165,10 +166,7 @@ def update_today(data):
165
166
s = data ["daily" ]["time" ][0 ] + data ["utc_offset_seconds" ]
166
167
t = time .localtime (s )
167
168
today_date .text = "{} {} {}, {}" .format (
168
- DAYS [t .tm_wday ].upper (),
169
- MONTHS [t .tm_mon - 1 ].upper (),
170
- t .tm_mday ,
171
- t .tm_year
169
+ DAYS [t .tm_wday ].upper (), MONTHS [t .tm_mon - 1 ].upper (), t .tm_mday , t .tm_year
172
170
)
173
171
# weather icon
174
172
w = data ["daily" ]["weather_code" ][0 ]
@@ -191,14 +189,14 @@ def update_future(data):
191
189
"""Update the future forecast info."""
192
190
for i , banner in enumerate (future_banners ):
193
191
# day of week
194
- s = data ["daily" ]["time" ][i + 1 ] + data ["utc_offset_seconds" ]
192
+ s = data ["daily" ]["time" ][i + 1 ] + data ["utc_offset_seconds" ]
195
193
t = time .localtime (s )
196
194
banner [0 ].text = DAYS [t .tm_wday ][:3 ].upper ()
197
195
# weather icon
198
- w = data ["daily" ]["weather_code" ][i + 1 ]
196
+ w = data ["daily" ]["weather_code" ][i + 1 ]
199
197
banner [1 ][0 ] = next (x for x , t in enumerate (WMO_CODE_TO_ICON ) if w in t )
200
198
# temperature
201
- t = data ["daily" ]["temperature_2m_max" ][i + 1 ]
199
+ t = data ["daily" ]["temperature_2m_max" ][i + 1 ]
202
200
banner [2 ].text = temperature_text (t )
203
201
204
202
@@ -303,8 +301,8 @@ def go_to_sleep(current_time_secs):
303
301
time .sleep (magtag .display .time_to_refresh + 1 )
304
302
305
303
print ("Sleeping..." )
306
- h , m , s = (int (t ) for t in resp_data .headers [' date' ].split (" " )[4 ].split (':' ))
307
- current_time_secs = (h * 3600 ) + (m * 60 ) + (s ) + forecast_data [' utc_offset_seconds' ]
304
+ h , m , s = (int (t ) for t in resp_data .headers [" date" ].split (" " )[4 ].split (":" ))
305
+ current_time_secs = (h * 3600 ) + (m * 60 ) + (s ) + forecast_data [" utc_offset_seconds" ]
308
306
go_to_sleep (current_time_secs )
309
307
# entire code will run again after deep sleep cycle
310
- # similar to hitting the reset button
308
+ # similar to hitting the reset button
0 commit comments