env-canada 0.9.0__py3-none-any.whl → 0.10.1__py3-none-any.whl
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.
- env_canada/ec_aqhi.py +21 -6
- {env_canada-0.9.0.dist-info → env_canada-0.10.1.dist-info}/METADATA +2 -2
- {env_canada-0.9.0.dist-info → env_canada-0.10.1.dist-info}/RECORD +6 -6
- {env_canada-0.9.0.dist-info → env_canada-0.10.1.dist-info}/WHEEL +0 -0
- {env_canada-0.9.0.dist-info → env_canada-0.10.1.dist-info}/licenses/LICENSE +0 -0
- {env_canada-0.9.0.dist-info → env_canada-0.10.1.dist-info}/top_level.txt +0 -0
env_canada/ec_aqhi.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
import logging
|
2
|
+
from dataclasses import dataclass
|
2
3
|
from datetime import datetime, timezone
|
3
4
|
|
4
5
|
import voluptuous as vol
|
5
|
-
from aiohttp import ClientSession
|
6
|
+
from aiohttp import ClientSession, ClientTimeout
|
6
7
|
from geopy import distance
|
7
8
|
from lxml import etree as et
|
8
9
|
|
@@ -12,6 +13,8 @@ AQHI_SITE_LIST_URL = "https://dd.weather.gc.ca/air_quality/doc/AQHI_XML_File_Lis
|
|
12
13
|
AQHI_OBSERVATION_URL = "https://dd.weather.gc.ca/air_quality/aqhi/{}/observation/realtime/xml/AQ_OBS_{}_CURRENT.xml"
|
13
14
|
AQHI_FORECAST_URL = "https://dd.weather.gc.ca/air_quality/aqhi/{}/forecast/realtime/xml/AQ_FCST_{}_CURRENT.xml"
|
14
15
|
|
16
|
+
CLIENT_TIMEOUT = ClientTimeout(10)
|
17
|
+
|
15
18
|
LOG = logging.getLogger(__name__)
|
16
19
|
|
17
20
|
ATTRIBUTION = {
|
@@ -20,6 +23,16 @@ ATTRIBUTION = {
|
|
20
23
|
}
|
21
24
|
|
22
25
|
|
26
|
+
@dataclass
|
27
|
+
class MetaData:
|
28
|
+
attribution: str
|
29
|
+
timestamp: datetime | None = None
|
30
|
+
location: str | None = None
|
31
|
+
|
32
|
+
# Not used; needed for compatability with ec_weather metadata
|
33
|
+
station: str | None = None
|
34
|
+
|
35
|
+
|
23
36
|
__all__ = ["ECAirQuality"]
|
24
37
|
|
25
38
|
|
@@ -39,7 +52,9 @@ async def get_aqhi_regions(language):
|
|
39
52
|
regions = []
|
40
53
|
async with ClientSession(raise_for_status=True) as session:
|
41
54
|
response = await session.get(
|
42
|
-
AQHI_SITE_LIST_URL,
|
55
|
+
AQHI_SITE_LIST_URL,
|
56
|
+
headers={"User-Agent": USER_AGENT},
|
57
|
+
timeout=CLIENT_TIMEOUT,
|
43
58
|
)
|
44
59
|
result = await response.read()
|
45
60
|
|
@@ -133,7 +148,7 @@ class ECAirQuality:
|
|
133
148
|
self.region_id = None
|
134
149
|
self.coordinates = kwargs["coordinates"]
|
135
150
|
|
136
|
-
self.metadata =
|
151
|
+
self.metadata = MetaData(ATTRIBUTION[self.language])
|
137
152
|
self.region_name = None
|
138
153
|
self.current = None
|
139
154
|
self.current_timestamp = None
|
@@ -145,7 +160,7 @@ class ECAirQuality:
|
|
145
160
|
response = await session.get(
|
146
161
|
url.format(self.zone_id, self.region_id),
|
147
162
|
headers={"User-Agent": USER_AGENT},
|
148
|
-
timeout=
|
163
|
+
timeout=CLIENT_TIMEOUT,
|
149
164
|
)
|
150
165
|
except Exception:
|
151
166
|
LOG.debug("Retrieving AQHI failed", exc_info=True)
|
@@ -177,7 +192,7 @@ class ECAirQuality:
|
|
177
192
|
self.region_name = element.attrib[
|
178
193
|
"name{lang}".format(lang=self.language.title())
|
179
194
|
]
|
180
|
-
self.metadata
|
195
|
+
self.metadata.location = self.region_name
|
181
196
|
|
182
197
|
# Update AQHI current condition
|
183
198
|
element = aqhi_current.find("airQualityHealthIndex")
|
@@ -191,7 +206,7 @@ class ECAirQuality:
|
|
191
206
|
self.current_timestamp = timestamp_to_datetime(element.text)
|
192
207
|
else:
|
193
208
|
self.current_timestamp = None
|
194
|
-
self.metadata
|
209
|
+
self.metadata.timestamp = self.current_timestamp
|
195
210
|
LOG.debug(
|
196
211
|
"update(): aqhi_current %d timestamp %s",
|
197
212
|
self.current,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: env_canada
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.10.1
|
4
4
|
Summary: A package to access meteorological data from Environment Canada
|
5
5
|
Author-email: Michael Davie <michael.davie@gmail.com>
|
6
6
|
Maintainer-email: Michael Davie <michael.davie@gmail.com>
|
@@ -36,7 +36,7 @@ Requires-Python: >=3.11
|
|
36
36
|
Description-Content-Type: text/markdown
|
37
37
|
License-File: LICENSE
|
38
38
|
Requires-Dist: aiohttp>=3.9.0
|
39
|
-
Requires-Dist: geopy>=2.
|
39
|
+
Requires-Dist: geopy>=2.3.0
|
40
40
|
Requires-Dist: imageio>=2.28.0
|
41
41
|
Requires-Dist: lxml>=5.3.0
|
42
42
|
Requires-Dist: numpy>=1.22.2
|
@@ -2,15 +2,15 @@ env_canada/10x20.pbm,sha256=ClKTs2WUmhUhTHAQzPuGwPTICGVBzCvos5l-vHRBE5M,2463
|
|
2
2
|
env_canada/10x20.pil,sha256=Oki6-TD7b0xFtfm6vxCKsmpEpsZ5Jaia_0v_aDz8bfE,5143
|
3
3
|
env_canada/__init__.py,sha256=O1KVC2GAPTmxAP46FXo9jd8Tq3YMefViowGjuxJ5JJM,366
|
4
4
|
env_canada/constants.py,sha256=RHa-Hp2H6XroFE9Z5-H0MIUPWlFXUVKmWEidwuWzakE,32
|
5
|
-
env_canada/ec_aqhi.py,sha256
|
5
|
+
env_canada/ec_aqhi.py,sha256=oE52qfk-AKbHdhTSl5RP3vsWL-50eMRCCRVy9RW-pP4,8080
|
6
6
|
env_canada/ec_cache.py,sha256=zb3n79ul7hUTE0IohDfZbRBLY-siOHPjYzWldMbuPVk,798
|
7
7
|
env_canada/ec_exc.py,sha256=SBJwzmLf94lTx7KYVLfQYrMXYNYUoIxeVXc-BLkuXoE,67
|
8
8
|
env_canada/ec_historical.py,sha256=qMr4RE6vfNiNa_zFolQ0PQGraok8bQtIVjs_o6sJKD4,16276
|
9
9
|
env_canada/ec_hydro.py,sha256=JoBe-QVV8GEeZXCNFscIs2R_spgkbxCZpLt7tL6-NUI,4889
|
10
10
|
env_canada/ec_radar.py,sha256=0SKusJWDTFODdn3D9yrhlkOS-Bv9hhBJM9EBh8TNRlk,12965
|
11
11
|
env_canada/ec_weather.py,sha256=l-gyXePkHBLW9vidFgiPEm81xevbZCeBKzKDLiLr7Y8,19200
|
12
|
-
env_canada-0.
|
13
|
-
env_canada-0.
|
14
|
-
env_canada-0.
|
15
|
-
env_canada-0.
|
16
|
-
env_canada-0.
|
12
|
+
env_canada-0.10.1.dist-info/licenses/LICENSE,sha256=BkgGIGgy9sv-OsI7mRi9dIQ3Su0m4IbjpZlfxv8oBbM,1073
|
13
|
+
env_canada-0.10.1.dist-info/METADATA,sha256=Cq1R2bbOithdmTqgbehba3Kqm6G1f-GbKxjKQWLs6XY,12710
|
14
|
+
env_canada-0.10.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
15
|
+
env_canada-0.10.1.dist-info/top_level.txt,sha256=fw7Pcl9ULBXYvqnAdyBdmwPXW8GSRFmhO0sLZWVfOCc,11
|
16
|
+
env_canada-0.10.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|