Files
boc/life-weather/providers/__pycache__/weather_provider.cpython-39.pyc
T

41 lines
3.0 KiB
Plaintext
Raw Normal View History

a
t%Ij× ã@sdZddlZddlZddlZddlmZddlmZedƒZejddGdd „d ƒZ e
d
kr~e ƒZ e   ¡Z
eeje
d d ƒdS)
u1
WeatherProvider - Hämtar väderdata från SMHI
éN)Údatetime)ÚPathz2/home/bernt/.openclaw/workspace/life-weather/cacheT)Úexist_okc@s@eZdZdddZdddZddZd d
Zd d Zd
dZdS)ÚWeatherProviderÚ97530cCs||_d|_dS)Nz;https://opendata-download-metobs.smhi.se/api/version/latest)Ú
station_idÚbase_url)Úselfr©r
úJ/home/bernt/.openclaw/workspace/life-weather/providers/weather_provider.pyÚ__init__szWeatherProvider.__init__éc Ct|ƒD]~}z8tj|dd}|jdkr4| ¡WSt d|¡Wqty„}z(||dkrbt d|¡WYd}~qd}~00qdS)uHämta data med retry-logiké
)ÚtimeoutéÈééN)ÚrangeÚrequestsÚgetZ status_codeÚjsonÚtimeÚsleepÚ Exception)r ÚurlZ max_retriesZattemptZresponseÚer
r
r Ú_fetch_with_retrys 
 &z!WeatherProvider._fetch_with_retrycCs|jd|jd}| |¡S)uHämta temperaturz/parameter/1/station/ú/period/latest-hour/data.json©rrr©r rr
r
r Úfetch_temperature!sz!WeatherProvider.fetch_temperaturecCs|jd|jd}| |¡S)uHämta nederbördz/parameter/7/station/z/period/latest-day/data.jsonrrr
r
r Úfetch_precipitation&sz#WeatherProvider.fetch_precipitationcCs|jd|jd}| |¡S)u Hämta vindz/parameter/4/station/rrrr
r
r Ú
fetch_wind+szWeatherProvider.fetch_windcCt ¡ ¡|jddddœ}| ¡}|r^d|vr^|d}|r^t|ddƒd|dddœ|d<| ¡}|r d|vr |d}|r td d
|Dƒƒ}|d d d
œ|d<| ¡}|räd|vrä|d}|rät|ddƒd|dddœ|d<|S)uHämta komplett väderbildN)Ú timestamprÚ temperatureÚ
precipitationÚwindÚvalueéÿÿÿÿÚcelsiusÚdate)r'Úunitr#r$css*|]"}t|dƒdkrt|dƒVqdS)r'rN)Úfloat)Ú.0Úvr
r
r Ú <genexpr>Hóz6WeatherProvider.get_current_weather.<locals>.<genexpr>Úmmz
latest-day)r'r+Zperiodr%zm/sr&) rÚnowÚ isoformatrr r,r!Úsumr")r ÚweatherZ temp_dataÚvaluesZ precip_dataÚtotalZ wind_datar
r
r Úget_current_weather0s@
û 
ý
 ý
 
ý
z#WeatherProvider.get_current_weatherN)r)r
) Ú__name__Ú
__module__Ú __qualname__r rr r!r"r8r
r