v.0.5.4 weather_checker, more details
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from app.classes.weather import Weather
|
||||
from app.display.neopixel_64x64 import NeoPixel_64x64
|
||||
from app.web.wlan import Wlan
|
||||
import app.utils.colors as colors
|
||||
@@ -22,7 +23,7 @@ class Weather_Checker():
|
||||
self.setup_wlan()
|
||||
|
||||
self.display.clear()
|
||||
self.display.set_font(fonts.font_3x5)
|
||||
# self.display.set_font(fonts.font_3x5)
|
||||
ypos = 0
|
||||
self.display.write_text('wlan connected', 0, ypos, color=colors.RAINBOW[0])
|
||||
ypos += self.display.font_height + 1
|
||||
@@ -30,15 +31,18 @@ class Weather_Checker():
|
||||
ypos += self.display.font_height + 1
|
||||
self.display.write_text('weather data', 0, ypos, color=colors.RAINBOW[2])
|
||||
|
||||
w_resp = self.wlan.actual_weather(lang='de', test_mode=test_mode)
|
||||
w_resp: Weather = self.wlan.actual_weather(lang='de', test_mode=test_mode)
|
||||
|
||||
self.display.clear()
|
||||
|
||||
ypos = 0
|
||||
self.display.write_text(f'{str(w_resp.location.name)}', 0, ypos, color=colors.RAINBOW[0])
|
||||
ypos += self.display.font_height + 1
|
||||
# self.display.set_font(fonts.font_8x8)
|
||||
self.display.set_font(fonts.font_5x7)
|
||||
self.display.write_text(f'{str(w_resp.location.region)}', 0, ypos, color=colors.RAINBOW[0])
|
||||
ypos += self.display.font_height + 1
|
||||
self.display.write_text(f'{str(w_resp.location.localtime)[:10]}', 0, ypos, color=colors.RAINBOW[3])
|
||||
ypos += self.display.font_height + 1
|
||||
|
||||
self.display.write_text(f'{str(w_resp.current.temp_c)}°C', 0, ypos, color=colors.RAINBOW[1])
|
||||
ypos += self.display.font_height + 1
|
||||
self.display.write_text(f'{str(w_resp.current.condition.text)}', 0, ypos, color=colors.RAINBOW[2])
|
||||
|
||||
@@ -9,70 +9,11 @@ API_KEY = '3545ce42d0ba436e8dc164532250410'
|
||||
ACTUAL_WEATHER_URL = 'http://api.weatherapi.com/v1/current.json?key={API_KEY}&q={city}&aqi=yes&lang={lang}'
|
||||
class Wlan:
|
||||
def __init__(self, ssid, password):
|
||||
self.wlan = network.WLAN(network.STA_IF)
|
||||
self.ssid = ssid
|
||||
self.password = password
|
||||
|
||||
def mock_weather_data(self):
|
||||
data = """
|
||||
{
|
||||
"location": {
|
||||
"name": "Grosshansdorf",
|
||||
"region": "Schleswig-Holstein",
|
||||
"country": "Germany",
|
||||
"lat": 53.6667,
|
||||
"lon": 10.2833,
|
||||
"tz_id": "Europe/Berlin",
|
||||
"localtime_epoch": 1760779328,
|
||||
"localtime": "2025-10-18 11:22"
|
||||
},
|
||||
"current": {
|
||||
"last_updated_epoch": 1760778900,
|
||||
"last_updated": "2025-10-18 11:15",
|
||||
"temp_c": 8.3,
|
||||
"temp_f": 46.9,
|
||||
"is_day": 1,
|
||||
"condition": {
|
||||
"text": "Sonnig",
|
||||
"icon": "//cdn.weatherapi.com/weather/64x64/day/113.png",
|
||||
"code": 1000
|
||||
},
|
||||
"wind_mph": 2.5,
|
||||
"wind_kph": 4.0,
|
||||
"wind_degree": 31,
|
||||
"wind_dir": "NNE",
|
||||
"pressure_mb": 1029.0,
|
||||
"pressure_in": 30.39,
|
||||
"precip_mm": 0.0,
|
||||
"precip_in": 0.0,
|
||||
"humidity": 76,
|
||||
"cloud": 0,
|
||||
"feelslike_c": 8.2,
|
||||
"feelslike_f": 46.8,
|
||||
"windchill_c": 10.0,
|
||||
"windchill_f": 50.0,
|
||||
"heatindex_c": 9.9,
|
||||
"heatindex_f": 49.8,
|
||||
"dewpoint_c": 2.2,
|
||||
"dewpoint_f": 35.9,
|
||||
"vis_km": 10.0,
|
||||
"vis_miles": 6.0,
|
||||
"uv": 0.9,
|
||||
"gust_mph": 2.8,
|
||||
"gust_kph": 4.6,
|
||||
"air_quality": {
|
||||
"co": 163.678,
|
||||
"no2": 7.278,
|
||||
"o3": 47.0,
|
||||
"so2": 1.178,
|
||||
"pm2_5": 5.778,
|
||||
"pm10": 7.178,
|
||||
"us-epa-index": 1,
|
||||
"gb-defra-index": 1
|
||||
}
|
||||
}
|
||||
}"""
|
||||
return json.loads(data)
|
||||
|
||||
filepath = 'restapi/mock-weather.json'
|
||||
try:
|
||||
with open(filepath, 'r', encoding='utf-8') as file:
|
||||
@@ -88,20 +29,21 @@ class Wlan:
|
||||
return None
|
||||
|
||||
def connect(self):
|
||||
wlan = network.WLAN(network.STA_IF)
|
||||
wlan.active(True)
|
||||
wlan.connect(self.ssid, self.password)
|
||||
|
||||
while not wlan.isconnected:
|
||||
self.wlan.active(True)
|
||||
self.wlan.connect(self.ssid, self.password)
|
||||
|
||||
while not self.wlan.isconnected:
|
||||
print('connecting, please wait ...')
|
||||
time.sleep(1)
|
||||
|
||||
print('connected! IP=', wlan.ifconfig()[0])
|
||||
print('connected! IP=', self.wlan.ifconfig()[0])
|
||||
|
||||
def actual_weather(self, city='grosshansdorf', lang='de', test_mode=False) -> Weather:
|
||||
weather_url = ACTUAL_WEATHER_URL.format(API_KEY=API_KEY, city=city, lang=lang)
|
||||
|
||||
if not test_mode:
|
||||
if not self.wlan.isconnected:
|
||||
self.connect()
|
||||
|
||||
print(f'query: {weather_url}')
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
{
|
||||
"location": {
|
||||
"name": "Grosshansdorf",
|
||||
"region": "Schleswig-Holstein",
|
||||
"country": "Germany",
|
||||
"lat": 53.6667,
|
||||
"lon": 10.2833,
|
||||
"tz_id": "Europe/Berlin",
|
||||
"localtime_epoch": 1761383733,
|
||||
"localtime": "2025-10-25 11:15"
|
||||
"name": "Columbus",
|
||||
"region": "Ohio",
|
||||
"country": "United States of America",
|
||||
"lat": 39.9611,
|
||||
"lon": -82.9989,
|
||||
"tz_id": "America/New_York",
|
||||
"localtime_epoch": 1762951576,
|
||||
"localtime": "2025-11-12 07:46"
|
||||
},
|
||||
"current": {
|
||||
"last_updated_epoch": 1761383700,
|
||||
"last_updated": "2025-10-25 11:15",
|
||||
"temp_c": 10.2,
|
||||
"temp_f": 50.4,
|
||||
"last_updated_epoch": 1762951500,
|
||||
"last_updated": "2025-11-12 07:45",
|
||||
"temp_c": 2.8,
|
||||
"temp_f": 37.0,
|
||||
"is_day": 1,
|
||||
"condition": {
|
||||
"text": "Overcast",
|
||||
"icon": "//cdn.weatherapi.com/weather/64x64/day/122.png",
|
||||
"code": 1009
|
||||
"text": "Partly cloudy",
|
||||
"icon": "//cdn.weatherapi.com/weather/64x64/day/116.png",
|
||||
"code": 1003
|
||||
},
|
||||
"wind_mph": 17.7,
|
||||
"wind_kph": 28.4,
|
||||
"wind_degree": 208,
|
||||
"wind_dir": "SSW",
|
||||
"pressure_mb": 991.0,
|
||||
"pressure_in": 29.26,
|
||||
"precip_mm": 0.03,
|
||||
"wind_mph": 11.6,
|
||||
"wind_kph": 18.7,
|
||||
"wind_degree": 235,
|
||||
"wind_dir": "SW",
|
||||
"pressure_mb": 1012.0,
|
||||
"pressure_in": 29.88,
|
||||
"precip_mm": 0.0,
|
||||
"precip_in": 0.0,
|
||||
"humidity": 82,
|
||||
"cloud": 100,
|
||||
"feelslike_c": 6.9,
|
||||
"feelslike_f": 44.5,
|
||||
"windchill_c": 5.4,
|
||||
"windchill_f": 41.8,
|
||||
"heatindex_c": 9.0,
|
||||
"heatindex_f": 48.3,
|
||||
"dewpoint_c": 6.3,
|
||||
"dewpoint_f": 43.4,
|
||||
"vis_km": 10.0,
|
||||
"vis_miles": 6.0,
|
||||
"uv": 0.1,
|
||||
"gust_mph": 25.3,
|
||||
"gust_kph": 40.7,
|
||||
"humidity": 67,
|
||||
"cloud": 75,
|
||||
"feelslike_c": -1.5,
|
||||
"feelslike_f": 29.2,
|
||||
"windchill_c": -2.1,
|
||||
"windchill_f": 28.2,
|
||||
"heatindex_c": 0.4,
|
||||
"heatindex_f": 32.6,
|
||||
"dewpoint_c": -2.2,
|
||||
"dewpoint_f": 28.0,
|
||||
"vis_km": 16.0,
|
||||
"vis_miles": 9.0,
|
||||
"uv": 0.0,
|
||||
"gust_mph": 18.3,
|
||||
"gust_kph": 29.5,
|
||||
"air_quality": {
|
||||
"co": 155.678,
|
||||
"no2": 9.678,
|
||||
"o3": 45.0,
|
||||
"so2": 2.078,
|
||||
"pm2_5": 4.678,
|
||||
"pm10": 6.178,
|
||||
"co": 216.85,
|
||||
"no2": 8.35,
|
||||
"o3": 54.0,
|
||||
"so2": 2.75,
|
||||
"pm2_5": 9.45,
|
||||
"pm10": 9.55,
|
||||
"us-epa-index": 1,
|
||||
"gb-defra-index": 1
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@city = "grosshansdorf"
|
||||
@city = "columbus"
|
||||
@lang = en
|
||||
@forecast_days = 3
|
||||
# could be 60(mins) or 24(day)
|
||||
|
||||
Reference in New Issue
Block a user