pygazpar 1.2.7__tar.gz → 1.3.0__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {pygazpar-1.2.7 → pygazpar-1.3.0}/CHANGELOG.md +15 -0
- pygazpar-1.2.7/LICENSE.md → pygazpar-1.3.0/LICENSE +21 -21
- pygazpar-1.3.0/PKG-INFO +225 -0
- {pygazpar-1.2.7 → pygazpar-1.3.0}/README.md +21 -14
- pygazpar-1.3.0/pygazpar/__init__.py +10 -0
- pygazpar-1.3.0/pygazpar/__main__.py +89 -0
- pygazpar-1.3.0/pygazpar/api_client.py +228 -0
- pygazpar-1.3.0/pygazpar/client.py +98 -0
- pygazpar-1.3.0/pygazpar/datasource.py +590 -0
- {pygazpar-1.2.7 → pygazpar-1.3.0}/pygazpar/excelparser.py +138 -136
- {pygazpar-1.2.7 → pygazpar-1.3.0}/pygazpar/jsonparser.py +53 -50
- pygazpar-1.3.0/pygazpar/version.py +3 -0
- pygazpar-1.3.0/pyproject.toml +66 -0
- pygazpar-1.2.7/MANIFEST.in +0 -5
- pygazpar-1.2.7/PKG-INFO +0 -476
- pygazpar-1.2.7/pygazpar/__init__.py +0 -4
- pygazpar-1.2.7/pygazpar/__main__.py +0 -83
- pygazpar-1.2.7/pygazpar/client.py +0 -59
- pygazpar-1.2.7/pygazpar/datasource.py +0 -522
- pygazpar-1.2.7/pygazpar/version.py +0 -1
- pygazpar-1.2.7/pygazpar.egg-info/PKG-INFO +0 -476
- pygazpar-1.2.7/pygazpar.egg-info/SOURCES.txt +0 -34
- pygazpar-1.2.7/pygazpar.egg-info/dependency_links.txt +0 -1
- pygazpar-1.2.7/pygazpar.egg-info/entry_points.txt +0 -2
- pygazpar-1.2.7/pygazpar.egg-info/not-zip-safe +0 -1
- pygazpar-1.2.7/pygazpar.egg-info/requires.txt +0 -3
- pygazpar-1.2.7/pygazpar.egg-info/top_level.txt +0 -3
- pygazpar-1.2.7/samples/__init__.py +0 -0
- pygazpar-1.2.7/samples/excelSample.py +0 -31
- pygazpar-1.2.7/samples/jsonSample.py +0 -30
- pygazpar-1.2.7/samples/testSample.py +0 -18
- pygazpar-1.2.7/setup.cfg +0 -54
- pygazpar-1.2.7/setup.py +0 -3
- pygazpar-1.2.7/tests/__init__.py +0 -0
- pygazpar-1.2.7/tests/test_client.py +0 -159
- pygazpar-1.2.7/tests/test_datafileparser.py +0 -20
- pygazpar-1.2.7/tests/test_datasource.py +0 -166
- {pygazpar-1.2.7 → pygazpar-1.3.0}/pygazpar/enum.py +0 -0
- {pygazpar-1.2.7 → pygazpar-1.3.0}/pygazpar/resources/daily_data_sample.json +0 -0
- {pygazpar-1.2.7 → pygazpar-1.3.0}/pygazpar/resources/hourly_data_sample.json +0 -0
- {pygazpar-1.2.7 → pygazpar-1.3.0}/pygazpar/resources/monthly_data_sample.json +0 -0
- {pygazpar-1.2.7 → pygazpar-1.3.0}/pygazpar/resources/weekly_data_sample.json +0 -0
- {pygazpar-1.2.7 → pygazpar-1.3.0}/pygazpar/resources/yearly_data_sample.json +0 -0
@@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [1.3.0] - 2025-02-15
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
[#84](https://github.com/ssenart/PyGazpar/issues/84) : Add a function to retrieve list of PCE ids.
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
|
15
|
+
[#85](https://github.com/ssenart/PyGazpar/issues/85) : Move to Poetry dependency/package management tool.
|
16
|
+
|
17
|
+
## [1.2.8](https://github.com/ssenart/PyGazpar/compare/1.2.8...1.2.7) - 2025-01-11
|
18
|
+
|
19
|
+
### Added
|
20
|
+
- [#81](https://github.com/ssenart/PyGazpar/issues/81): Add meter/temperature debug log messages to help investigation in case of errors.
|
21
|
+
|
7
22
|
## [1.2.7](https://github.com/ssenart/PyGazpar/compare/1.2.7...1.2.6) - 2025-01-06
|
8
23
|
|
9
24
|
### Fixed
|
@@ -1,21 +1,21 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c)
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Stéphane Senart
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
pygazpar-1.3.0/PKG-INFO
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: pygazpar
|
3
|
+
Version: 1.3.0
|
4
|
+
Summary: Python library to download gas consumption from a GrDF (French Gas Company) account
|
5
|
+
License: MIT License
|
6
|
+
|
7
|
+
Copyright (c) 2025 Stéphane Senart
|
8
|
+
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
11
|
+
in the Software without restriction, including without limitation the rights
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
14
|
+
furnished to do so, subject to the following conditions:
|
15
|
+
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
17
|
+
copies or substantial portions of the Software.
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
25
|
+
SOFTWARE.
|
26
|
+
Author: Stéphane Senart
|
27
|
+
Requires-Python: >=3.10
|
28
|
+
Classifier: Programming Language :: Python :: 3.10
|
29
|
+
Classifier: Programming Language :: Python :: 3.11
|
30
|
+
Classifier: Programming Language :: Python :: 3.12
|
31
|
+
Classifier: Programming Language :: Python :: 3.13
|
32
|
+
Requires-Dist: openpyxl (>=3.1.5,<4.0.0)
|
33
|
+
Requires-Dist: pandas (>=2.1.4,<3.0.0)
|
34
|
+
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
35
|
+
Description-Content-Type: text/markdown
|
36
|
+
|
37
|
+
# PyGazpar
|
38
|
+
|
39
|
+
PyGazpar is a Python library for getting natural gas consumption from GrDF French provider.
|
40
|
+
|
41
|
+
Their natural gas meter is called Gazpar. It is wireless and transmit the gas consumption once per day.
|
42
|
+
|
43
|
+
All consumption data is available on the client account at GrDF Web Site (https://monespace.grdf.fr).
|
44
|
+
|
45
|
+
PyGazpar automatically goes through the Web Site and download the consumption data, and make it available in a Python structure.
|
46
|
+
|
47
|
+
## Installation
|
48
|
+
|
49
|
+
### Requirements
|
50
|
+
PyGazpar does not require Selenium and corresponding geckodriver to work.
|
51
|
+
|
52
|
+
With the new GrDF web site, it is possible to load the consumption data far easily than before.
|
53
|
+
|
54
|
+
PyGazpar uses [Poetry](https://python-poetry.org/) for dependency and package management.
|
55
|
+
|
56
|
+
### Create your virtual environment
|
57
|
+
|
58
|
+
```bash
|
59
|
+
$ cd /path/to/my_project_folder/
|
60
|
+
|
61
|
+
$ poetry install
|
62
|
+
```
|
63
|
+
|
64
|
+
### PyGazpar installation
|
65
|
+
|
66
|
+
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install PyGazpar.
|
67
|
+
|
68
|
+
```bash
|
69
|
+
pip install pygazpar
|
70
|
+
```
|
71
|
+
|
72
|
+
You can also download the source code and install it manually.
|
73
|
+
```bash
|
74
|
+
cd /path/to/pygazpar/
|
75
|
+
|
76
|
+
$ poetry install
|
77
|
+
```
|
78
|
+
|
79
|
+
## Usage
|
80
|
+
|
81
|
+
#### Command line:
|
82
|
+
|
83
|
+
1. Standard usage (using Json GrDF API).
|
84
|
+
|
85
|
+
```bash
|
86
|
+
$ pygazpar -u 'your login' -p 'your password' -c 'your PCE identifier' --datasource 'json'
|
87
|
+
```
|
88
|
+
|
89
|
+
2. Alternate usage (using Excel GrDF document).
|
90
|
+
|
91
|
+
```bash
|
92
|
+
$ pygazpar -u 'your login' -p 'your password' -c 'your PCE identifier' -t 'temporary directory where to store Excel file (ex: /tmp)' --datasource 'excel'
|
93
|
+
```
|
94
|
+
|
95
|
+
3. Test usage (using local static data files, do not connect to GrDF site).
|
96
|
+
|
97
|
+
```bash
|
98
|
+
$ pygazpar -u 'your login' -p 'your password' -c 'your PCE identifier' --datasource 'test'
|
99
|
+
```
|
100
|
+
|
101
|
+
#### Library:
|
102
|
+
|
103
|
+
1. Standard usage (using Json GrDF API).
|
104
|
+
|
105
|
+
```python
|
106
|
+
import pygazpar
|
107
|
+
|
108
|
+
client = pygazpar.Client(pygazpar.JsonWebDataSource(
|
109
|
+
username='your login',
|
110
|
+
password='your password')
|
111
|
+
)
|
112
|
+
|
113
|
+
# Returns the list of your PCE identifiers attached to your account.
|
114
|
+
pce_identifiers = client.get_pce_identifiers()
|
115
|
+
|
116
|
+
# Returns the daily and monthly consumptions for the last 60 days on your PCE identifier.
|
117
|
+
data = client.load_since(pce_identifier='your PCE identifier',
|
118
|
+
last_n_days=60,
|
119
|
+
frequencies=[pygazpar.Frequency.DAILY, pygazpar.Frequency.MONTHLY])
|
120
|
+
```
|
121
|
+
See [samples/jsonSample.py](samples/jsonSample.py) file for the full example.
|
122
|
+
|
123
|
+
2. Alternate usage (using Excel GrDF document).
|
124
|
+
|
125
|
+
```python
|
126
|
+
import pygazpar
|
127
|
+
|
128
|
+
client = pygazpar.Client(pygazpar.ExcelWebDataSource(
|
129
|
+
username='your login',
|
130
|
+
password='your password')
|
131
|
+
)
|
132
|
+
|
133
|
+
# Returns the list of your PCE identifiers attached to your account.
|
134
|
+
pce_identifiers = client.get_pce_identifiers()
|
135
|
+
|
136
|
+
# Returns the daily and monthly consumptions for the last 60 days on your PCE identifier.
|
137
|
+
data = client.load_since(pce_identifier='your PCE identifier',
|
138
|
+
last_n_days=60,
|
139
|
+
frequencies=[pygazpar.Frequency.DAILY, pygazpar.Frequency.MONTHLY])
|
140
|
+
```
|
141
|
+
See [samples/excelSample.py](samples/jsonSample.py) file for the full example.
|
142
|
+
|
143
|
+
3. Test usage (using local static data files, do not connect to GrDF site).
|
144
|
+
|
145
|
+
```python
|
146
|
+
import pygazpar
|
147
|
+
|
148
|
+
client = pygazpar.Client(pygazpar.TestDataSource())
|
149
|
+
|
150
|
+
data = client.load_since(pce_identifier='your PCE identifier',
|
151
|
+
last_n_days=10,
|
152
|
+
frequencies=[pygazpar.Frequency.DAILY, Frequency.MONTHLY])
|
153
|
+
```
|
154
|
+
See [samples/testSample.py](samples/jsonSample.py) file for the full example.
|
155
|
+
|
156
|
+
#### Output:
|
157
|
+
|
158
|
+
```json
|
159
|
+
data =>
|
160
|
+
{
|
161
|
+
"daily": [
|
162
|
+
{
|
163
|
+
"time_period": "13/10/2022",
|
164
|
+
"start_index_m3": 15724,
|
165
|
+
"end_index_m3": 15725,
|
166
|
+
"volume_m3": 2,
|
167
|
+
"energy_kwh": 17,
|
168
|
+
"converter_factor_kwh/m3": 11.16,
|
169
|
+
"temperature_degC": null,
|
170
|
+
"type": "Mesur\u00e9",
|
171
|
+
"timestamp": "2022-12-13T23:58:35.606763"
|
172
|
+
},
|
173
|
+
...
|
174
|
+
{
|
175
|
+
"time_period": "11/12/2022",
|
176
|
+
"start_index_m3": 16081,
|
177
|
+
"end_index_m3": 16098,
|
178
|
+
"volume_m3": 18,
|
179
|
+
"energy_kwh": 201,
|
180
|
+
"converter_factor_kwh/m3": 11.27,
|
181
|
+
"temperature_degC": -1.47,
|
182
|
+
"type": "Mesur\u00e9",
|
183
|
+
"timestamp": "2022-12-13T23:58:35.606763"
|
184
|
+
}
|
185
|
+
],
|
186
|
+
"monthly": [
|
187
|
+
{
|
188
|
+
"time_period": "Novembre 2022",
|
189
|
+
"start_index_m3": 15750,
|
190
|
+
"end_index_m3": 15950,
|
191
|
+
"volume_m3": 204,
|
192
|
+
"energy_kwh": 2227,
|
193
|
+
"timestamp": "2022-12-13T23:58:35.606763"
|
194
|
+
},
|
195
|
+
{
|
196
|
+
"time_period": "D\u00e9cembre 2022",
|
197
|
+
"start_index_m3": 15950,
|
198
|
+
"end_index_m3": 16098,
|
199
|
+
"volume_m3": 148,
|
200
|
+
"energy_kwh": 1664,
|
201
|
+
"timestamp": "2022-12-13T23:58:35.606763"
|
202
|
+
}
|
203
|
+
]
|
204
|
+
}
|
205
|
+
```
|
206
|
+
|
207
|
+
## Limitation
|
208
|
+
PyGazpar relies on how GrDF Web Site is built.
|
209
|
+
|
210
|
+
Any change in the Web site may break this library.
|
211
|
+
|
212
|
+
We expect in close Future that GrDF makes available an open API from which we can get safely their data.
|
213
|
+
|
214
|
+
## Contributing
|
215
|
+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
216
|
+
|
217
|
+
Please make sure to update tests as appropriate.
|
218
|
+
|
219
|
+
## License
|
220
|
+
[MIT](https://choosealicense.com/licenses/mit/)
|
221
|
+
|
222
|
+
## Project status
|
223
|
+
PyGazpar has been initiated for integration with [Home Assistant](https://www.home-assistant.io/).
|
224
|
+
|
225
|
+
Corresponding Home Assistant integration custom component is available [here](https://github.com/ssenart/home-assistant-gazpar).
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# PyGazpar
|
2
2
|
|
3
|
-
## $\text{\color{green}{!!! This library is working again. CAPTCHA has been removed !!!}}$
|
4
|
-
|
5
3
|
PyGazpar is a Python library for getting natural gas consumption from GrDF French provider.
|
6
4
|
|
7
5
|
Their natural gas meter is called Gazpar. It is wireless and transmit the gas consumption once per day.
|
@@ -17,20 +15,20 @@ PyGazpar does not require Selenium and corresponding geckodriver to work.
|
|
17
15
|
|
18
16
|
With the new GrDF web site, it is possible to load the consumption data far easily than before.
|
19
17
|
|
18
|
+
PyGazpar uses [Poetry](https://python-poetry.org/) for dependency and package management.
|
19
|
+
|
20
20
|
### Create your virtual environment
|
21
|
+
|
21
22
|
```bash
|
22
23
|
$ cd /path/to/my_project_folder/
|
23
24
|
|
24
|
-
$
|
25
|
+
$ poetry install
|
25
26
|
```
|
26
27
|
|
27
28
|
### PyGazpar installation
|
28
|
-
Activate your virtual environment.
|
29
|
-
```bash
|
30
|
-
source .venv/bin/activate
|
31
|
-
```
|
32
29
|
|
33
30
|
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install PyGazpar.
|
31
|
+
|
34
32
|
```bash
|
35
33
|
pip install pygazpar
|
36
34
|
```
|
@@ -38,7 +36,8 @@ pip install pygazpar
|
|
38
36
|
You can also download the source code and install it manually.
|
39
37
|
```bash
|
40
38
|
cd /path/to/pygazpar/
|
41
|
-
|
39
|
+
|
40
|
+
$ poetry install
|
42
41
|
```
|
43
42
|
|
44
43
|
## Usage
|
@@ -75,8 +74,12 @@ client = pygazpar.Client(pygazpar.JsonWebDataSource(
|
|
75
74
|
password='your password')
|
76
75
|
)
|
77
76
|
|
78
|
-
|
79
|
-
|
77
|
+
# Returns the list of your PCE identifiers attached to your account.
|
78
|
+
pce_identifiers = client.get_pce_identifiers()
|
79
|
+
|
80
|
+
# Returns the daily and monthly consumptions for the last 60 days on your PCE identifier.
|
81
|
+
data = client.load_since(pce_identifier='your PCE identifier',
|
82
|
+
last_n_days=60,
|
80
83
|
frequencies=[pygazpar.Frequency.DAILY, pygazpar.Frequency.MONTHLY])
|
81
84
|
```
|
82
85
|
See [samples/jsonSample.py](samples/jsonSample.py) file for the full example.
|
@@ -91,8 +94,12 @@ client = pygazpar.Client(pygazpar.ExcelWebDataSource(
|
|
91
94
|
password='your password')
|
92
95
|
)
|
93
96
|
|
94
|
-
|
95
|
-
|
97
|
+
# Returns the list of your PCE identifiers attached to your account.
|
98
|
+
pce_identifiers = client.get_pce_identifiers()
|
99
|
+
|
100
|
+
# Returns the daily and monthly consumptions for the last 60 days on your PCE identifier.
|
101
|
+
data = client.load_since(pce_identifier='your PCE identifier',
|
102
|
+
last_n_days=60,
|
96
103
|
frequencies=[pygazpar.Frequency.DAILY, pygazpar.Frequency.MONTHLY])
|
97
104
|
```
|
98
105
|
See [samples/excelSample.py](samples/jsonSample.py) file for the full example.
|
@@ -104,8 +111,8 @@ import pygazpar
|
|
104
111
|
|
105
112
|
client = pygazpar.Client(pygazpar.TestDataSource())
|
106
113
|
|
107
|
-
data = client.
|
108
|
-
|
114
|
+
data = client.load_since(pce_identifier='your PCE identifier',
|
115
|
+
last_n_days=10,
|
109
116
|
frequencies=[pygazpar.Frequency.DAILY, Frequency.MONTHLY])
|
110
117
|
```
|
111
118
|
See [samples/testSample.py](samples/jsonSample.py) file for the full example.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
from pygazpar.client import Client # noqa: F401
|
2
|
+
from pygazpar.datasource import ( # noqa: F401
|
3
|
+
ExcelFileDataSource,
|
4
|
+
ExcelWebDataSource,
|
5
|
+
JsonFileDataSource,
|
6
|
+
JsonWebDataSource,
|
7
|
+
TestDataSource,
|
8
|
+
)
|
9
|
+
from pygazpar.enum import Frequency, PropertyName # noqa: F401
|
10
|
+
from pygazpar.version import __version__ # noqa: F401
|
@@ -0,0 +1,89 @@
|
|
1
|
+
import argparse
|
2
|
+
import json
|
3
|
+
import logging
|
4
|
+
import os
|
5
|
+
import sys
|
6
|
+
import traceback
|
7
|
+
|
8
|
+
import pygazpar
|
9
|
+
|
10
|
+
Logger = logging.getLogger(__name__)
|
11
|
+
|
12
|
+
|
13
|
+
def main():
|
14
|
+
"""Main function"""
|
15
|
+
parser = argparse.ArgumentParser()
|
16
|
+
parser.add_argument("-v", "--version", action="version", version=f"PyGazpar {pygazpar.__version__}")
|
17
|
+
parser.add_argument("-u", "--username", required=True, help="GRDF username (email)")
|
18
|
+
parser.add_argument("-p", "--password", required=True, help="GRDF password")
|
19
|
+
parser.add_argument("-c", "--pce", required=True, help="GRDF PCE identifier")
|
20
|
+
parser.add_argument("-t", "--tmpdir", required=False, default="/tmp", help="tmp directory (default is /tmp)")
|
21
|
+
parser.add_argument(
|
22
|
+
"-f",
|
23
|
+
"--frequency",
|
24
|
+
required=False,
|
25
|
+
type=lambda frequency: pygazpar.Frequency[frequency],
|
26
|
+
choices=list(pygazpar.Frequency),
|
27
|
+
default="DAILY",
|
28
|
+
help="Meter reading frequency (DAILY, WEEKLY, MONTHLY, YEARLY)",
|
29
|
+
)
|
30
|
+
parser.add_argument(
|
31
|
+
"-d",
|
32
|
+
"--lastNDays",
|
33
|
+
required=False,
|
34
|
+
type=int,
|
35
|
+
default=365,
|
36
|
+
help="Get only the last N days of records (default: 365 days)",
|
37
|
+
)
|
38
|
+
parser.add_argument("--datasource", required=False, default="json", help="Datasource: json | excel | test")
|
39
|
+
|
40
|
+
args = parser.parse_args()
|
41
|
+
|
42
|
+
print(f"PyGazpar version: {pygazpar.__version__}")
|
43
|
+
print(f"Running on Python version: {sys.version}")
|
44
|
+
|
45
|
+
# We create the tmp directory if not already exists.
|
46
|
+
if not os.path.exists(args.tmpdir):
|
47
|
+
os.mkdir(args.tmpdir)
|
48
|
+
|
49
|
+
# We remove the pygazpar log file.
|
50
|
+
pygazparLogFile = f"{args.tmpdir}/pygazpar.log"
|
51
|
+
if os.path.isfile(pygazparLogFile):
|
52
|
+
os.remove(pygazparLogFile)
|
53
|
+
|
54
|
+
# Setup logging.
|
55
|
+
logging.basicConfig(
|
56
|
+
filename=f"{pygazparLogFile}", level=logging.DEBUG, format="%(asctime)s %(levelname)s [%(name)s] %(message)s"
|
57
|
+
)
|
58
|
+
|
59
|
+
Logger.info(f"PyGazpar version: {pygazpar.__version__}")
|
60
|
+
Logger.info(f"Running on Python version: {sys.version}")
|
61
|
+
Logger.info(f"--tmpdir {args.tmpdir}")
|
62
|
+
Logger.info(f"--frequency {args.frequency}")
|
63
|
+
Logger.info(f"--lastNDays {args.lastNDays}")
|
64
|
+
Logger.info(f"--datasource {bool(args.datasource)}")
|
65
|
+
|
66
|
+
if args.datasource == "json":
|
67
|
+
client = pygazpar.Client(pygazpar.JsonWebDataSource(args.username, args.password))
|
68
|
+
elif args.datasource == "excel":
|
69
|
+
client = pygazpar.Client(pygazpar.ExcelWebDataSource(args.username, args.password, args.tmpdir))
|
70
|
+
elif args.datasource == "test":
|
71
|
+
client = pygazpar.Client(pygazpar.TestDataSource())
|
72
|
+
else:
|
73
|
+
raise ValueError("Invalid datasource: (json | excel | test) is expected")
|
74
|
+
|
75
|
+
try:
|
76
|
+
data = client.load_since(args.pce, int(args.lastNDays), [args.frequency])
|
77
|
+
except BaseException: # pylint: disable=broad-except
|
78
|
+
print("An error occured while querying PyGazpar library : %s", traceback.format_exc())
|
79
|
+
return 1
|
80
|
+
|
81
|
+
Logger.info(f"Data loaded: {len(data)} records")
|
82
|
+
Logger.debug(f"Data: {data}")
|
83
|
+
print(json.dumps(data, indent=2))
|
84
|
+
|
85
|
+
return 0
|
86
|
+
|
87
|
+
|
88
|
+
if __name__ == "__main__":
|
89
|
+
sys.exit(main())
|