hamsclientfork 0.2.15__tar.gz → 0.2.17__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hamsclientfork
3
- Version: 0.2.15
3
+ Version: 0.2.17
4
4
  Summary: Library to get data from meteo swiss
5
5
  Home-page: https://github.com/Rudd-O/hamsclientfork
6
6
  Author: websylv
@@ -34,6 +34,9 @@ MS_SEARCH_URL = "https://www.meteosuisse.admin.ch/home/actualite/infos.html?ort=
34
34
  CURRENT_CONDITION_URL = (
35
35
  "https://data.geo.admin.ch/ch.meteoschweiz.messwerte-aktuell/VQHA80.csv"
36
36
  )
37
+ CURRENT_PRECIPITATION_URL = (
38
+ "https://data.geo.admin.ch/ch.meteoschweiz.messwerte-aktuell/VQHA98.csv"
39
+ )
37
40
  STATION_URL = "https://data.geo.admin.ch/ch.meteoschweiz.messnetz-automatisch/ch.meteoschweiz.messnetz-automatisch_fr.csv"
38
41
  STATION_TYPE_PRECIPITATION = "Précipitation"
39
42
  STATION_TYPE_WEATHER = "Station météo"
@@ -157,33 +160,33 @@ class CurrentCondition(TypedDict):
157
160
 
158
161
  def CurrentCondition_from_meteoswiss_data(data: dict[str, Any]) -> CurrentCondition:
159
162
  def floatornone(val: Any) -> float | None:
160
- if val == "" or val == "-":
163
+ if val == "" or val == "-" or val is None:
161
164
  return None
162
165
  return float(val)
163
166
 
164
167
  return CurrentCondition(
165
168
  station=data["Station/Location"],
166
169
  date=int(data["Date"]),
167
- tre200s0=floatornone(data["tre200s0"]),
168
- rre150z0=floatornone(data["rre150z0"]),
169
- sre000z0=floatornone(data["sre000z0"]),
170
- gre000z0=floatornone(data["gre000z0"]),
171
- ure200s0=floatornone(data["ure200s0"]),
172
- tde200s0=floatornone(data["tde200s0"]),
173
- dkl010z0=floatornone(data["dkl010z0"]),
174
- fu3010z0=floatornone(data["fu3010z0"]),
175
- fu3010z1=floatornone(data["fu3010z1"]),
176
- prestas0=floatornone(data["prestas0"]),
177
- pp0qffs0=floatornone(data["pp0qffs0"]),
178
- pp0qnhs0=floatornone(data["pp0qnhs0"]),
179
- ppz850s0=floatornone(data["ppz850s0"]),
180
- ppz700s0=floatornone(data["ppz700s0"]),
181
- dv1towz0=floatornone(data["dv1towz0"]),
182
- fu3towz0=floatornone(data["fu3towz0"]),
183
- fu3towz1=floatornone(data["fu3towz1"]),
184
- ta1tows0=floatornone(data["ta1tows0"]),
185
- uretows0=floatornone(data["uretows0"]),
186
- tdetows0=floatornone(data["tdetows0"]),
170
+ tre200s0=floatornone(data.get("tre200s0")),
171
+ rre150z0=floatornone(data.get("rre150z0")),
172
+ sre000z0=floatornone(data.get("sre000z0")),
173
+ gre000z0=floatornone(data.get("gre000z0")),
174
+ ure200s0=floatornone(data.get("ure200s0")),
175
+ tde200s0=floatornone(data.get("tde200s0")),
176
+ dkl010z0=floatornone(data.get("dkl010z0")),
177
+ fu3010z0=floatornone(data.get("fu3010z0")),
178
+ fu3010z1=floatornone(data.get("fu3010z1")),
179
+ prestas0=floatornone(data.get("prestas0")),
180
+ pp0qffs0=floatornone(data.get("pp0qffs0")),
181
+ pp0qnhs0=floatornone(data.get("pp0qnhs0")),
182
+ ppz850s0=floatornone(data.get("ppz850s0")),
183
+ ppz700s0=floatornone(data.get("ppz700s0")),
184
+ dv1towz0=floatornone(data.get("dv1towz0")),
185
+ fu3towz0=floatornone(data.get("fu3towz0")),
186
+ fu3towz1=floatornone(data.get("fu3towz1")),
187
+ ta1tows0=floatornone(data.get("ta1tows0")),
188
+ uretows0=floatornone(data.get("uretows0")),
189
+ tdetows0=floatornone(data.get("tdetows0")),
187
190
  )
188
191
 
189
192
 
@@ -192,7 +195,7 @@ class ClientResult(TypedDict):
192
195
  forecast: Forecast
193
196
  # A list of current conditions for the first station passed.
194
197
  condition: list[CurrentCondition]
195
- # A dictionary of station -> list of the current condition
198
+ # A dictionary of station -> list of the current precipitation
196
199
  # returned by the corresponding station.
197
200
  condition_by_station: dict[str, CurrentCondition]
198
201
 
@@ -218,6 +221,8 @@ class meteoSwissClient:
218
221
  self._allStations: dict[str, Any] | None = None
219
222
  self._condition = None
220
223
  self._conditions: dict[str, Any] = {}
224
+ self._precipitation = None
225
+ self._precipitations: dict[str, Any] = {}
221
226
  self._forecast = None
222
227
  _LOGGER.debug(
223
228
  "INIT meteoswiss client : name = %s stations = %s postcode = %s"
@@ -293,12 +298,30 @@ class meteoSwissClient:
293
298
  lines = response.text.split("\n")
294
299
  csv_reader = csv.DictReader(lines, delimiter=";")
295
300
  data = [row for row in csv_reader if row]
301
+ with requests.get(CURRENT_PRECIPITATION_URL) as response:
302
+ response.raise_for_status()
303
+ response.encoding = "iso_8859_1"
304
+ lines = response.text.split("\n")
305
+ csv_reader = csv.DictReader(lines, delimiter=";")
306
+ rain_data = [row for row in csv_reader if row]
296
307
  conditions = {}
297
308
  condition_list = []
298
309
  for station in self._stations:
299
310
  _LOGGER.debug("Get current condition for : %s" % station)
300
- stationData = data.loc[data["Station/Location"].str.contains(station)]
301
- stationData = stationData.to_dict("records")
311
+ stationData = [d for d in data if d["Station/Location"] == station]
312
+ rainData = [d for d in rain_data if d["Station/Location"] == station]
313
+ if rainData and not stationData:
314
+ stationData = rainData
315
+ elif rainData and stationData:
316
+ # Add all values from the rain data to the station data.
317
+ for k, v in rainData.items():
318
+ stationData[k] = v
319
+ else:
320
+ # if
321
+ # (stationData and not rainData)
322
+ # or
323
+ # (not stationData and not rainData)
324
+ pass
302
325
  condition_list.extend(stationData)
303
326
  if stationData:
304
327
  conditions[station] = stationData[0]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hamsclientfork
3
- Version: 0.2.15
3
+ Version: 0.2.17
4
4
  Summary: Library to get data from meteo swiss
5
5
  Home-page: https://github.com/Rudd-O/hamsclientfork
6
6
  Author: websylv
@@ -15,7 +15,7 @@ def read(filename):
15
15
 
16
16
  setup(
17
17
  name="hamsclientfork",
18
- version="0.2.15",
18
+ version="0.2.17",
19
19
  url="https://github.com/Rudd-O/hamsclientfork",
20
20
  license="MIT",
21
21
  author="websylv",
File without changes
File without changes