v.0.4.7 mock_weather_data return as json

This commit is contained in:
tiijay
2025-11-11 11:35:30 +01:00
parent a9eead6e9e
commit ae3fe54db9

View File

@@ -1,14 +1,12 @@
import time import time
import network import network # type: ignore
import urequests import urequests # type: ignore
from ..classes.location import Location from ..classes.location import Location
from ..classes.weather import CurrentCondition, Weather from ..classes.weather import CurrentCondition, Weather
import json import json
API_KEY = '3545ce42d0ba436e8dc164532250410' API_KEY = '3545ce42d0ba436e8dc164532250410'
ACTUAL_WEATHER = 'https://api.weatherapi.com/v1/current.json?key={{key}}&q={{city}}&aqi=yes' ACTUAL_WEATHER_URL = 'http://api.weatherapi.com/v1/current.json?key={API_KEY}&q={city}&aqi=yes&lang={lang}'
class Wlan: class Wlan:
def __init__(self, ssid, password): def __init__(self, ssid, password):
self.ssid = ssid self.ssid = ssid
@@ -73,6 +71,7 @@ class Wlan:
} }
} }
}""" }"""
return json.loads(data)
filepath = 'restapi/mock-weather.json' filepath = 'restapi/mock-weather.json'
try: try:
@@ -100,9 +99,7 @@ class Wlan:
print('connected! IP=', wlan.ifconfig()[0]) print('connected! IP=', wlan.ifconfig()[0])
def actual_weather(self, city='grosshansdorf', lang='de', test_mode=False) -> Weather: def actual_weather(self, city='grosshansdorf', lang='de', test_mode=False) -> Weather:
weather_url = ( weather_url = ACTUAL_WEATHER_URL.format(API_KEY=API_KEY, city=city, lang=lang)
f'https://api.weatherapi.com/v1/current.json?key={API_KEY}&q={city}&aqi=yes&lang={lang}'
)
if not test_mode: if not test_mode:
self.connect() self.connect()