meteocatpy 0.0.15 → 0.0.16

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## [0.0.16](https://github.com/figorr/meteocatpy/compare/v0.0.15...v0.0.16) (2024-12-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * 0.0.16 ([a59edbc](https://github.com/figorr/meteocatpy/commit/a59edbcff6297346113b411405122b9fe6e9fe14))
7
+ * fix installation at README ([15e4651](https://github.com/figorr/meteocatpy/commit/15e46517254c0f9bdd82adf8038a17ae6e4339d5))
8
+ * ignore uvi test json file ([87189ce](https://github.com/figorr/meteocatpy/commit/87189cea76510a75fa41c015aa522075ba71d19f))
9
+ * improve data recovery when invalid date ([3b72e7e](https://github.com/figorr/meteocatpy/commit/3b72e7e1aeb34485e1226c56f2b6cce385b19f38))
10
+ * json file name ([6e97de1](https://github.com/figorr/meteocatpy/commit/6e97de1d585c17936b316eb1fcc1b5ac2b5275d9))
11
+
1
12
  ## [0.0.15](https://github.com/figorr/meteocatpy/compare/v0.0.14...v0.0.15) (2024-12-13)
2
13
 
3
14
 
package/README.md CHANGED
@@ -17,14 +17,14 @@ pip install meteocatpy
17
17
  ```
18
18
 
19
19
  ```bash
20
- from meteocatpy.client import MeteocatClient
20
+ from meteocatpy.town import MeteocatTown
21
21
 
22
22
  # Replace 'tu_api_key' with your actual API key
23
23
  api_key = "tu_api_key"
24
- client = MeteocatClient(api_key)
24
+ town_client = MeteocatTown(api_key)
25
25
 
26
26
  # Get a list of municipalities (asynchronous call)
27
- municipis = await client.get_municipis()
27
+ municipios_data = await town_client.get_municipis()
28
28
  print(municipis)
29
29
  ```
30
30
 
@@ -1,5 +1,6 @@
1
1
  import aiohttp
2
2
  import logging
3
+ import re
3
4
  from datetime import datetime
4
5
  from .variables import MeteocatVariables
5
6
  from .const import BASE_URL, STATION_DATA_URL
@@ -64,6 +65,23 @@ class MeteocatStationData:
64
65
 
65
66
  # Gestionar errores según el código de estado
66
67
  if response.status == 400:
68
+ error_data = await response.json()
69
+ # Intentar extraer la última fecha válida del mensaje de error
70
+ if "message" in error_data:
71
+ match = re.search(r'entre (\d{2}-\d{2}-\d{4}) i', error_data["message"])
72
+ if match:
73
+ last_valid_date = match.group(1) # Captura la última fecha válida
74
+ dia, mes, any = map(int, last_valid_date.split('-'))
75
+ # Intentar nuevamente con la última fecha válida
76
+ new_url = f"{BASE_URL}{STATION_DATA_URL}".format(
77
+ codiEstacio=station_id, any=any, mes=f"{mes:02d}", dia=f"{dia:02d}"
78
+ )
79
+ async with session.get(new_url, headers=self.headers) as new_response:
80
+ if new_response.status == 200:
81
+ return await new_response.json()
82
+ raise UnknownAPIError(
83
+ f"Failed with the valid date {last_valid_date}: {await new_response.text()}"
84
+ )
67
85
  raise BadRequestError(await response.json())
68
86
  elif response.status == 403:
69
87
  error_data = await response.json()
@@ -1,2 +1,2 @@
1
1
  # version.py
2
- __version__ = "0.0.15"
2
+ __version__ = "0.0.16"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meteocatpy",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\r [![Python version compatibility](https://img.shields.io/pypi/pyversions/meteocatpy)](https://pypi.org/project/meteocatpy)\r [![pipeline status](https://gitlab.com/figorr/meteocatpy/badges/master/pipeline.svg)](https://gitlab.com/figorr/meteocatpy/commits/master)",
5
5
  "main": "index.js",
6
6
  "directories": {
package/pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "meteocatpy"
3
- version = "0.0.15"
3
+ version = "0.0.16"
4
4
  description = "Script para obtener datos meteorológicos de la API de Meteocat"
5
5
  authors = ["figorr <jdcuartero@yahoo.es>"]
6
6
  license = "Apache-2.0"
@@ -8,7 +8,7 @@ from meteocatpy.uvi import MeteocatUviData
8
8
  load_dotenv()
9
9
 
10
10
  # Obtener los valores del archivo .env
11
- API_KEY = os.getenv("METEOCAT_API_KEY")
11
+ API_KEY = os.getenv("METEOCAT_API_KEY_TEST")
12
12
  MUNICIPI_CODI_TEST = os.getenv("MUNICIPI_CODI_TEST")
13
13
 
14
14
  # Asegúrate de que las variables estén definidas
@@ -27,7 +27,7 @@ async def test_municipis():
27
27
  os.makedirs('tests/files', exist_ok=True)
28
28
 
29
29
  # Guardar los datos del índice UVI en un archivo JSON
30
- with open(f'tests/files/uvi_index_{MUNICIPI_CODI_TEST}.json', 'w', encoding='utf-8') as f:
30
+ with open(f'tests/files/uvi_{MUNICIPI_CODI_TEST}_data.json', 'w', encoding='utf-8') as f:
31
31
  json.dump(uvi_data, f, ensure_ascii=False, indent=4)
32
32
 
33
33
  # Verificar que los datos del índice UVI no estén vacíos