Retrieve gas consumption from GrDF web site (French Gas Company)
Project description
PyGazpar
PyGazpar is a Python library for getting natural gas consumption from GrDF French provider.
Their natural gas meter is called Gazpar. It is wireless and transmit the gas consumption once per day.
All consumption data is available on the client account at GrDF Web Site (https://monespace.grdf.fr).
PyGazpar automatically go through the Web Site and download the consumption data Excel file, and make it available in a Python structure (list of dictionaries).
Installation
Requirements
PyGazpar is working with Selenium Python library to automate navigation through GrDF Web site. Selenium requires a WebDriver that acts as gateway between automatic actions from PyGazpar and a native browser already installed on the system.
PyGazpar has been developped and tested with Firefox browser (version 68.8) and its corresponding Web Driver geckodriver (version 0.24).
Firefox browser installation
Follow instructions here
Firefox Web Driver (geckodriver) installation
Follow instructions here
Create your virtual environment
$ pip install virtualenv
$ cd /path/to/my_project_folder/
$ virtualenv venv
PyGazpar installation
Use the package manager pip to install PyGazpar.
pip install pygazpar
You can also download the source code and install it manually.
cd /path/to/pygazpar/
python setup.py install
Usage
Command line
$ pygazpar -u 'your login' -p 'your password' -w 'path/to/Selenium Web Driver' -s 30 -t 'temporary directory where to store XSLX file (ex: /tmp)'
Library
import pygazpar
client = pygazpar.Client('your login',
'your password',
'path/to/Selenium Web Driver',
30,
'temporary directory where to store XSLX file (ex: /tmp)')
client.update()
data = client.data()
Output
data =>
[
{
"date": "01/07/2019",
"start_index_m3": 9802.0,
"end_index_m3": 9805.0,
"volume_m3": 3.6,
"energy_kwh": 40.0,
"converter_factor": "11,244",
"local_temperature": "",
"type": "MES",
"timestamp": "2019-08-29T16:56:07.380422"
},
{
"date": "02/07/2019",
"start_index_m3": 9805.0,
"end_index_m3": 9808.0,
"volume_m3": 2.8,
"energy_kwh": 31.0,
"converter_factor": "11,244",
"local_temperature": "21",
"type": "MES",
"timestamp": "2019-08-29T16:56:07.380422"
},
{
"date": "03/07/2019",
"start_index_m3": 9808.0,
"end_index_m3": 9811.0,
"volume_m3": 2.9,
"energy_kwh": 33.0,
"converter_factor": "11,244",
"local_temperature": "",
"type": "MES",
"timestamp": "2019-08-29T16:56:07.380422"
}
]
Limitation
PyGazpar relies on how GrDF Web Site is built. It goes through each Web pages and automatically fill forms, click buttons using their internal identifiers.
Any change in the Web site structure or identifier naming may break this library.
We expect in close Future that GrDF makes available a standard API from which we can get safely their data.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
Project status
PyGazpar has been initiated for integration with Home Assistant.
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
0.1.23 - 2021-04-09
Changed
- Final release with CI/CD workflow improvement.
0.1.22 - 2021-04-09
Changed
- Improve CI/CD workflow.
0.1.21 - 2021-04-07
Changed
- Cleanup some codes managing Privacy Conditions popup.
0.1.20 - 2021-04-07
Changed
- Close an eventual Privacy Conditions popup just before clicking the daily button (instead of Cookie banner).
0.1.19 - 2021-04-06
Added
- Close an eventual Cookie popup just before clicking the daily button.
- Add log messages and screenshot capture around click() and send_keys() methods.
0.1.18 - 2021-04-05
Fixed
- Typo in logger usage.
0.1.17 - 2021-04-05
Fixed
- Logger name must be different in each instance. Using name is a good practice, we can get the module hierarchy.
0.1.16 - 2021-04-05
Fixed
- Logger 'pygazpar' initialization must be done inside the main program and not inside the library.
0.1.15 - 2021-04-05
Added
- Many log message to help debugging if GrDF site changes something : pygazpar.log
- Take a screenshot of the corresponding page where a selenium command fails : error_screenshot.png.
0.1.14 - 2020-09-23
Fixed
- GrDF survey popup has to be closed at the home page.
- GrDF Assistant popup may hide the Download button. We have to close it.
- GrDF bottom banner that invite to accept cookies may also hide the Download button. We have to accept it.
Added
- A new parameter 'lastNRows' to get only the last N most recent records.
0.1.13 - 2020-06-30
Fixed
- GrDF data retrieval from Excel file is not limited to the 1000 first rows any more.
0.1.12 - 2020-06-30
Fixed
- The previous 0.1.11 is not sufficient. Hence, 2 new changes : First, make configurable the waiting time so the user can adapt to its context usage. Second, the condition on clicking on Download button is now based on the corresponding event and not anymore on its identifier.
0.1.11 - 2020-06-29
Fixed
- When GrDF Web site is slower than usual, the client may not wait enough time for pages to load and miss to reach the data file. It occurs with the page containing 'Jour' button which is very long to load (I increase the wait to load time from 5s to 30s).
0.1.10 - 2020-06-03
Fixed
- Extract rows from Excel until line 1000 (instead of 365 as before).
0.1.9 - 2019-08-31
Fixed
- WebDriver window size must be large enough to display all clickable components.
0.1.8 - 2019-08-31
Changed
- Use PropertyNameEnum type to store all property names.
0.1.7 - 2019-08-29
Added
- Add wait_time option to control how much time the library has to wait for Web page element to load (see https://selenium-python.readthedocs.io/waits.html for details).
- Add LoginError exception raised when PyGazpar is unable to sign in the GrDF Web site with the given username/password.
- Refactor all data property names.
0.1.6 - 2019-08-26
Added
- Add README.md and CHANGELOG.md.
- Add Client.data() method to get the updated data.
Removed
- Remove Client.data property to get the updated data. Replaced with Client.__data private property.
MIT License
Copyright (c) 2019 Stéphane Senart
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for pygazpar-0.1.23-py39-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3db4eb24aacdac85b85b87e0f41dcfcd6c0d596ba7e3186b79edbd2bccaedda9 |
|
MD5 | a64fb7e436c58bb77681a91f14c17368 |
|
BLAKE2b-256 | 93924e517cbd77a36a26e45ccc14f4bea51456ff28d91556438fc2791728d6d1 |
Hashes for pygazpar-0.1.23-py38-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44bf33ad48a499ce589e9dbaf59d57468f91d6889019855d790899a69fbda6b9 |
|
MD5 | ff2d66956c0b0d0c16568a714e00bce8 |
|
BLAKE2b-256 | 5850b92bc8cb21d85909128a7e057ad667df35a86839b7f02274636900e560f5 |
Hashes for pygazpar-0.1.23-py37-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 121a74dfa314ef5d3d4ed41cce0848f297435a2e568bb65e00534bff759939a2 |
|
MD5 | a495d86f2a2cdabd33aa5bcd9e8de103 |
|
BLAKE2b-256 | 28cbcd19adf19a5cfe1f50223d54bb8a7fdddbaf2ecdbfd2106470b682a782e0 |
Hashes for pygazpar-0.1.23-py36-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf263affd394472f55168bdf4e748b0a22cd695cb11548e57bb53029175143ce |
|
MD5 | d7727985c8e73737da9e8731cd5e7724 |
|
BLAKE2b-256 | 2bc5dc102b18deca52e9aef159bee2a86e870cd6b27a5299c9edccfc3566a5ec |