pygazpar 1.3.0a12__py38-none-any.whl → 1.3.0a14__py38-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- pygazpar/datasource.py +13 -29
- pygazpar/jsonparser.py +1 -1
- pygazpar/version.py +1 -1
- {pygazpar-1.3.0a12.dist-info → pygazpar-1.3.0a14.dist-info}/METADATA +11 -1
- {pygazpar-1.3.0a12.dist-info → pygazpar-1.3.0a14.dist-info}/RECORD +10 -10
- {pygazpar-1.3.0a12.dist-info → pygazpar-1.3.0a14.dist-info}/WHEEL +1 -1
- tests/test_client.py +14 -0
- {pygazpar-1.3.0a12.dist-info → pygazpar-1.3.0a14.dist-info}/LICENSE.md +0 -0
- {pygazpar-1.3.0a12.dist-info → pygazpar-1.3.0a14.dist-info}/entry_points.txt +0 -0
- {pygazpar-1.3.0a12.dist-info → pygazpar-1.3.0a14.dist-info}/top_level.txt +0 -0
pygazpar/datasource.py
CHANGED
@@ -59,9 +59,9 @@ class WebDataSource(IDataSource):
|
|
59
59
|
# ------------------------------------------------------
|
60
60
|
def load(self, pceIdentifier: str, startDate: date, endDate: date, frequencies: Optional[List[Frequency]] = None) -> MeterReadingsByFrequency:
|
61
61
|
|
62
|
-
|
62
|
+
self._login(self.__username, self.__password) # We ignore the return value.
|
63
63
|
|
64
|
-
res = self._loadFromSession(
|
64
|
+
res = self._loadFromSession(pceIdentifier, startDate, endDate, frequencies)
|
65
65
|
|
66
66
|
Logger.debug("The data update terminates normally")
|
67
67
|
|
@@ -88,23 +88,23 @@ class WebDataSource(IDataSource):
|
|
88
88
|
|
89
89
|
jar = http.cookiejar.CookieJar()
|
90
90
|
|
91
|
-
|
92
|
-
|
93
|
-
|
91
|
+
self._session = Session()
|
92
|
+
self._session.headers.update({"Content-Type": "application/json"})
|
93
|
+
self._session.headers.update({"X-Requested-With": "XMLHttpRequest"})
|
94
94
|
|
95
95
|
params = json.loads(AUTH_TOKEN_PARAMS.format(session_token))
|
96
96
|
|
97
|
-
response =
|
97
|
+
response = self._session.get(AUTH_TOKEN_URL, params=params, allow_redirects=True, cookies=jar) # type: ignore
|
98
98
|
|
99
99
|
if response.status_code != 200:
|
100
100
|
raise Exception(f"An error occurred while getting the auth token. Status code: {response.status_code} - {response.text}")
|
101
101
|
|
102
|
-
auth_token =
|
102
|
+
auth_token = self._session.cookies.get("auth_token", domain="monespace.grdf.fr")
|
103
103
|
|
104
104
|
return auth_token # type: ignore
|
105
105
|
|
106
106
|
@abstractmethod
|
107
|
-
def _loadFromSession(self,
|
107
|
+
def _loadFromSession(self, pceIdentifier: str, startDate: date, endDate: date, frequencies: Optional[List[Frequency]] = None) -> MeterReadingsByFrequency:
|
108
108
|
pass
|
109
109
|
|
110
110
|
|
@@ -133,7 +133,7 @@ class ExcelWebDataSource(WebDataSource):
|
|
133
133
|
self.__tmpDirectory = tmpDirectory
|
134
134
|
|
135
135
|
# ------------------------------------------------------
|
136
|
-
def _loadFromSession(self,
|
136
|
+
def _loadFromSession(self, pceIdentifier: str, startDate: date, endDate: date, frequencies: Optional[List[Frequency]] = None) -> MeterReadingsByFrequency:
|
137
137
|
|
138
138
|
res = {}
|
139
139
|
|
@@ -166,16 +166,8 @@ class ExcelWebDataSource(WebDataSource):
|
|
166
166
|
retry = 10
|
167
167
|
while retry > 0:
|
168
168
|
|
169
|
-
# Create a session.
|
170
|
-
session = Session()
|
171
|
-
session.headers.update({"Host": "monespace.grdf.fr"})
|
172
|
-
session.headers.update({"Domain": "grdf.fr"})
|
173
|
-
session.headers.update({"X-Requested-With": "XMLHttpRequest"})
|
174
|
-
session.headers.update({"Accept": "application/json"})
|
175
|
-
session.cookies.set("auth_token", auth_token, domain="monespace.grdf.fr")
|
176
|
-
|
177
169
|
try:
|
178
|
-
self.__downloadFile(
|
170
|
+
self.__downloadFile(self._session, downloadUrl, self.__tmpDirectory)
|
179
171
|
break
|
180
172
|
except Exception as e:
|
181
173
|
|
@@ -267,7 +259,7 @@ class JsonWebDataSource(WebDataSource):
|
|
267
259
|
|
268
260
|
super().__init__(username, password)
|
269
261
|
|
270
|
-
def _loadFromSession(self,
|
262
|
+
def _loadFromSession(self, pceIdentifier: str, startDate: date, endDate: date, frequencies: Optional[List[Frequency]] = None) -> MeterReadingsByFrequency:
|
271
263
|
|
272
264
|
res = {}
|
273
265
|
|
@@ -286,16 +278,8 @@ class JsonWebDataSource(WebDataSource):
|
|
286
278
|
retry = 10
|
287
279
|
while retry > 0:
|
288
280
|
|
289
|
-
# Create a session.
|
290
|
-
session = Session()
|
291
|
-
session.headers.update({"Host": "monespace.grdf.fr"})
|
292
|
-
session.headers.update({"Domain": "grdf.fr"})
|
293
|
-
session.headers.update({"X-Requested-With": "XMLHttpRequest"})
|
294
|
-
session.headers.update({"Accept": "application/json"})
|
295
|
-
session.cookies.set("auth_token", auth_token, domain="monespace.grdf.fr")
|
296
|
-
|
297
281
|
try:
|
298
|
-
response =
|
282
|
+
response = self._session.get(downloadUrl)
|
299
283
|
|
300
284
|
if "text/html" in response.headers.get("Content-Type"): # type: ignore
|
301
285
|
raise Exception("An error occurred while loading data. Please check your credentials.")
|
@@ -321,7 +305,7 @@ class JsonWebDataSource(WebDataSource):
|
|
321
305
|
temperaturesUrl = JsonWebDataSource.TEMPERATURES_URL.format(pceIdentifier, endDate.strftime(JsonWebDataSource.INPUT_DATE_FORMAT), days)
|
322
306
|
|
323
307
|
# Get weather data.
|
324
|
-
temperatures =
|
308
|
+
temperatures = self._session.get(temperaturesUrl).text
|
325
309
|
|
326
310
|
# Transform all the data into the target structure.
|
327
311
|
daily = JsonParser.parse(data, temperatures, pceIdentifier)
|
pygazpar/jsonparser.py
CHANGED
@@ -29,7 +29,7 @@ class JsonParser:
|
|
29
29
|
|
30
30
|
for releve in data[pceIdentifier]['releves']:
|
31
31
|
temperature = releve['temperature']
|
32
|
-
if temperature is None:
|
32
|
+
if temperature is None and temperatures is not None and len(temperatures) > 0:
|
33
33
|
temperature = temperatures.get(releve['journeeGaziere'])
|
34
34
|
|
35
35
|
item = {}
|
pygazpar/version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "1.3.
|
1
|
+
__version__ = "1.3.0a14"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: pygazpar
|
3
|
-
Version: 1.3.
|
3
|
+
Version: 1.3.0a14
|
4
4
|
Summary: Retrieve gas consumption from GrDF web site (French Gas Company)
|
5
5
|
Home-page: https://github.com/ssenart/pygazpar
|
6
6
|
Author: Stephane Senart
|
@@ -219,6 +219,16 @@ All notable changes to this project will be documented in this file.
|
|
219
219
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
220
220
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
221
221
|
|
222
|
+
## [1.2.6](https://github.com/ssenart/PyGazpar/compare/1.2.6...1.2.5) - 2025-01-03
|
223
|
+
|
224
|
+
### Fixed
|
225
|
+
- [#77](https://github.com/ssenart/PyGazpar/issues/77): Some error may occur while requesting data from GrDF API.
|
226
|
+
|
227
|
+
## [1.2.5](https://github.com/ssenart/PyGazpar/compare/1.2.5...1.2.4) - 2024-12-21
|
228
|
+
|
229
|
+
### Fixed
|
230
|
+
- [#75](https://github.com/ssenart/PyGazpar/issues/75): Fix an error when no temperature data is available.
|
231
|
+
|
222
232
|
## [1.2.4](https://github.com/ssenart/PyGazpar/compare/1.2.4...1.2.3) - 2024-10-09
|
223
233
|
|
224
234
|
### Fixed
|
@@ -1,11 +1,11 @@
|
|
1
1
|
pygazpar/__init__.py,sha256=qshO_XZbDA2Wrt80ABDs0MoScqJytClAuIJjAnILglk,309
|
2
2
|
pygazpar/__main__.py,sha256=Pt3PInX7QiWcs0aBKZN90NTaU8KFnrQiZ5Hsow1eR5U,3177
|
3
3
|
pygazpar/client.py,sha256=JdVm0jZbeibwtTumcRbUSFadfXnCUClPMjL95_J6p5Y,2595
|
4
|
-
pygazpar/datasource.py,sha256=
|
4
|
+
pygazpar/datasource.py,sha256=D6VBy4ngQDECQfPVi9ZGhKuuOxNDUHjK-9gTDJlATPI,20699
|
5
5
|
pygazpar/enum.py,sha256=3ZCk4SziXF6pxgP3MuQ1qxYfqB3X5DOV8Rtd0GHsK9w,898
|
6
6
|
pygazpar/excelparser.py,sha256=QNFIErXNgMjGGjsGjdnRxAbNpfVagdYmZQtXRub3_Xc,5931
|
7
|
-
pygazpar/jsonparser.py,sha256=
|
8
|
-
pygazpar/version.py,sha256=
|
7
|
+
pygazpar/jsonparser.py,sha256=OrRdMZNBi7rI4dRGoRW7gjyFwJFk-IvtkRZ_t1XVFrI,1859
|
8
|
+
pygazpar/version.py,sha256=PmDAmw10ADg9AEzlwKqIjkV015azg3jlJE14KxjkD10,25
|
9
9
|
pygazpar/resources/daily_data_sample.json,sha256=YJovtrNUMs257magTfyxiewLmecySFypcelbGFUUeT8,199583
|
10
10
|
pygazpar/resources/hourly_data_sample.json,sha256=N1F-Xz3GaBn2H1p7uKzhkhKCQV8QVR0t76XD6wmFtXA,3
|
11
11
|
pygazpar/resources/monthly_data_sample.json,sha256=yrr4SqrB2MubeVU2HX_FRDZKHIhC0LXCqkO1iqnFWcg,3351
|
@@ -16,12 +16,12 @@ samples/excelSample.py,sha256=ltAl-bBz9-U9YI802JpcIswra-vDS7tR_KL5VNdxJ5c,765
|
|
16
16
|
samples/jsonSample.py,sha256=sYAIusdEJhZdwDAMgHqoWcwDR0FA2eWhSt_2gL_mJRk,736
|
17
17
|
samples/testSample.py,sha256=UeirdEtezHwfZDv_75oxul17YzGWn5yZuHfJYTF3Ez0,387
|
18
18
|
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
19
|
-
tests/test_client.py,sha256=
|
19
|
+
tests/test_client.py,sha256=UiJCqy_Nctl_YDSVpdaYfrbUEzuu9Td22a4WxNnIhJw,5606
|
20
20
|
tests/test_datafileparser.py,sha256=nAeUpOHtelblMpmbrrnf-2GuMjK5ai65veDoymceprE,818
|
21
21
|
tests/test_datasource.py,sha256=Fkn9BOGVKITAgrx9XipR1_ykT7rdvPyt_PAg3ftjfSU,5983
|
22
|
-
pygazpar-1.3.
|
23
|
-
pygazpar-1.3.
|
24
|
-
pygazpar-1.3.
|
25
|
-
pygazpar-1.3.
|
26
|
-
pygazpar-1.3.
|
27
|
-
pygazpar-1.3.
|
22
|
+
pygazpar-1.3.0a14.dist-info/LICENSE.md,sha256=XsCJx_7_BC9tvmE0ZxS1cTNR7ekurog_ea9ybdZ-8tc,1073
|
23
|
+
pygazpar-1.3.0a14.dist-info/METADATA,sha256=kopg_-Iz7kQQTUdCjUQ-tOHh-T-ZIQC5rP0VcDXkbL4,19133
|
24
|
+
pygazpar-1.3.0a14.dist-info/WHEEL,sha256=bkapPWmaLinkcP210NpibBONXH5ryQB77NZphDx-h5Y,93
|
25
|
+
pygazpar-1.3.0a14.dist-info/entry_points.txt,sha256=c_FMZPYlRv1w9EqfgWhlkdJOoje7FcglI0UMm2oRLoI,53
|
26
|
+
pygazpar-1.3.0a14.dist-info/top_level.txt,sha256=P7qn-XtanDPBLQsTvjvLV71wH8RK0DYbx8tzN_rDS70,23
|
27
|
+
pygazpar-1.3.0a14.dist-info/RECORD,,
|
tests/test_client.py
CHANGED
@@ -52,6 +52,20 @@ class TestClient:
|
|
52
52
|
|
53
53
|
assert (len(data[Frequency.HOURLY.value]) == 0)
|
54
54
|
|
55
|
+
def test_one_day_jsonweb(self):
|
56
|
+
client = Client(JsonWebDataSource(self.__username, self.__password))
|
57
|
+
|
58
|
+
data = client.loadSince(self.__pceIdentifier, 1, [Frequency.DAILY])
|
59
|
+
|
60
|
+
assert (len(data[Frequency.DAILY.value]) <= 1)
|
61
|
+
|
62
|
+
def test_two_days_jsonweb(self):
|
63
|
+
client = Client(JsonWebDataSource(self.__username, self.__password))
|
64
|
+
|
65
|
+
data = client.loadSince(self.__pceIdentifier, 2, [Frequency.DAILY])
|
66
|
+
|
67
|
+
assert (len(data[Frequency.DAILY.value]) <= 2)
|
68
|
+
|
55
69
|
# @pytest.mark.skip(reason="Requires live data")
|
56
70
|
def test_daily_jsonweb(self):
|
57
71
|
client = Client(JsonWebDataSource(self.__username, self.__password))
|
File without changes
|
File without changes
|
File without changes
|