hamsclientfork 0.2.10__tar.gz → 0.2.12__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hamsclientfork-0.2.10/hamsclientfork.egg-info → hamsclientfork-0.2.12}/PKG-INFO +1 -1
- {hamsclientfork-0.2.10 → hamsclientfork-0.2.12}/hamsclientfork/client.py +51 -8
- {hamsclientfork-0.2.10 → hamsclientfork-0.2.12/hamsclientfork.egg-info}/PKG-INFO +1 -1
- {hamsclientfork-0.2.10 → hamsclientfork-0.2.12}/setup.py +1 -1
- {hamsclientfork-0.2.10 → hamsclientfork-0.2.12}/.gitignore +0 -0
- {hamsclientfork-0.2.10 → hamsclientfork-0.2.12}/LICENSE +0 -0
- {hamsclientfork-0.2.10 → hamsclientfork-0.2.12}/README.md +0 -0
- {hamsclientfork-0.2.10 → hamsclientfork-0.2.12}/README.rst +0 -0
- {hamsclientfork-0.2.10 → hamsclientfork-0.2.12}/hamsclientfork/__init__.py +0 -0
- {hamsclientfork-0.2.10 → hamsclientfork-0.2.12}/hamsclientfork/__main__.py +0 -0
- {hamsclientfork-0.2.10 → hamsclientfork-0.2.12}/hamsclientfork/py.typed +0 -0
- {hamsclientfork-0.2.10 → hamsclientfork-0.2.12}/hamsclientfork.egg-info/SOURCES.txt +0 -0
- {hamsclientfork-0.2.10 → hamsclientfork-0.2.12}/hamsclientfork.egg-info/dependency_links.txt +0 -0
- {hamsclientfork-0.2.10 → hamsclientfork-0.2.12}/hamsclientfork.egg-info/requires.txt +0 -0
- {hamsclientfork-0.2.10 → hamsclientfork-0.2.12}/hamsclientfork.egg-info/top_level.txt +0 -0
- {hamsclientfork-0.2.10 → hamsclientfork-0.2.12}/setup.cfg +0 -0
- {hamsclientfork-0.2.10 → hamsclientfork-0.2.12}/tox.ini +0 -0
|
@@ -4,6 +4,7 @@ import json
|
|
|
4
4
|
import logging
|
|
5
5
|
import pandas as pd
|
|
6
6
|
import requests # type: ignore
|
|
7
|
+
import datetime
|
|
7
8
|
|
|
8
9
|
from bs4 import BeautifulSoup
|
|
9
10
|
from enum import Enum
|
|
@@ -28,7 +29,7 @@ _HEADERS = {
|
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
MS_BASE_URL = "https://www.meteosuisse.admin.ch"
|
|
31
|
-
JSON_FORECAST_URL = "https://app-prod-ws.meteoswiss-app.ch/v1/forecast?plz={}00&
|
|
32
|
+
JSON_FORECAST_URL = "https://app-prod-ws.meteoswiss-app.ch/v1/forecast?plz={}00&graph_startLowResolution=true&warning=true"
|
|
32
33
|
MS_SEARCH_URL = "https://www.meteosuisse.admin.ch/home/actualite/infos.html?ort={}&pageIndex=0&tab=search_tab"
|
|
33
34
|
CURRENT_CONDITION_URL = (
|
|
34
35
|
"https://data.geo.admin.ch/ch.meteoschweiz.messwerte-aktuell/VQHA80.csv"
|
|
@@ -70,19 +71,62 @@ def DayForecast_from_meteoswiss_data(data: dict[str, Any]) -> DayForecast:
|
|
|
70
71
|
)
|
|
71
72
|
|
|
72
73
|
|
|
74
|
+
class HourlyForecast(TypedDict):
|
|
75
|
+
time: datetime.datetime
|
|
76
|
+
temperatureMax: float
|
|
77
|
+
temperatureMean: float
|
|
78
|
+
temperatureMin: float
|
|
79
|
+
precipitationMax: float
|
|
80
|
+
precipitationMean: float
|
|
81
|
+
precipitationMin: float
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def HourlyForecast_from_meteoswiss_data(data: dict[str, Any]) -> list[HourlyForecast]:
|
|
85
|
+
time = datetime.datetime.fromtimestamp(
|
|
86
|
+
data["start"] / 1000, tz=datetime.timezone.utc
|
|
87
|
+
)
|
|
88
|
+
results: list[HourlyForecast] = []
|
|
89
|
+
for idx in range(
|
|
90
|
+
min(
|
|
91
|
+
[
|
|
92
|
+
len(data["temperatureMin1h"]),
|
|
93
|
+
len(data["temperatureMax1h"]),
|
|
94
|
+
len(data["temperatureMean1h"]),
|
|
95
|
+
len(data["precipitationMin1h"]),
|
|
96
|
+
len(data["precipitationMean1h"]),
|
|
97
|
+
len(data["precipitationMax1h"]),
|
|
98
|
+
]
|
|
99
|
+
)
|
|
100
|
+
):
|
|
101
|
+
d = HourlyForecast(
|
|
102
|
+
time=time,
|
|
103
|
+
temperatureMax=data["temperatureMax1h"][idx],
|
|
104
|
+
temperatureMean=data["temperatureMean1h"][idx],
|
|
105
|
+
temperatureMin=data["temperatureMin1h"][idx],
|
|
106
|
+
precipitationMin=data["precipitationMin1h"][idx],
|
|
107
|
+
precipitationMean=data["precipitationMean1h"][idx],
|
|
108
|
+
precipitationMax=data["precipitationMax1h"][idx],
|
|
109
|
+
)
|
|
110
|
+
results.append(d)
|
|
111
|
+
time = time + datetime.timedelta(hours=1)
|
|
112
|
+
return results
|
|
113
|
+
|
|
114
|
+
|
|
73
115
|
class Forecast(TypedDict):
|
|
74
116
|
plz: str
|
|
75
117
|
currentWeather: CurrentWeather
|
|
76
118
|
regionForecast: list[DayForecast]
|
|
119
|
+
regionHourlyForecast: list[HourlyForecast]
|
|
77
120
|
|
|
78
121
|
|
|
79
|
-
def Forecast_from_meteoswiss_data(data: dict[str, Any]):
|
|
122
|
+
def Forecast_from_meteoswiss_data(data: dict[str, Any]) -> Forecast:
|
|
80
123
|
return Forecast(
|
|
81
124
|
plz=data["plz"],
|
|
82
125
|
currentWeather=data["currentWeather"],
|
|
83
126
|
regionForecast=[
|
|
84
127
|
DayForecast_from_meteoswiss_data(x) for x in data["regionForecast"]
|
|
85
128
|
],
|
|
129
|
+
regionHourlyForecast=HourlyForecast_from_meteoswiss_data(data["graph"]),
|
|
86
130
|
)
|
|
87
131
|
|
|
88
132
|
|
|
@@ -145,7 +189,7 @@ def CurrentCondition_from_meteoswiss_data(data: dict[str, Any]) -> CurrentCondit
|
|
|
145
189
|
|
|
146
190
|
class ClientResult(TypedDict):
|
|
147
191
|
name: str
|
|
148
|
-
forecast:
|
|
192
|
+
forecast: Forecast
|
|
149
193
|
condition: list[CurrentCondition]
|
|
150
194
|
|
|
151
195
|
|
|
@@ -218,19 +262,18 @@ class meteoSwissClient:
|
|
|
218
262
|
_LOGGER.debug("End of 24 forecast udate")
|
|
219
263
|
|
|
220
264
|
def get_forecast(self):
|
|
221
|
-
_LOGGER.debug("Start update forecast data")
|
|
222
265
|
s = requests.Session()
|
|
223
266
|
# Forcing headers to avoid 500 error when downloading file
|
|
224
267
|
s.headers.update(_HEADERS)
|
|
225
268
|
|
|
226
269
|
jsonUrl = JSON_FORECAST_URL.format(self._postCode)
|
|
270
|
+
_LOGGER.debug("Start update forecast data with URL %s", jsonUrl)
|
|
227
271
|
jsonData = s.get(jsonUrl, timeout=10)
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
jsonObj = json.loads(jsonDataTxt)
|
|
272
|
+
jsonData.raise_for_status()
|
|
273
|
+
jsonObj = jsonData.json()
|
|
231
274
|
|
|
232
275
|
self._forecast = jsonObj
|
|
233
|
-
_LOGGER.debug("End of forecast
|
|
276
|
+
_LOGGER.debug("End of forecast update")
|
|
234
277
|
|
|
235
278
|
def get_current_condition(self):
|
|
236
279
|
_LOGGER.debug("Update current condition")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hamsclientfork-0.2.10 → hamsclientfork-0.2.12}/hamsclientfork.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|