pygazpar 1.2.7__py312-none-any.whl → 1.2.8__py312-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.
pygazpar/excelparser.py CHANGED
@@ -1,136 +1,138 @@
1
- import logging
2
- from datetime import datetime
3
- from pygazpar.enum import Frequency
4
- from pygazpar.enum import PropertyName
5
- from openpyxl.worksheet.worksheet import Worksheet
6
- from openpyxl.cell.cell import Cell
7
- from openpyxl import load_workbook
8
- from typing import Any, List, Dict
9
-
10
-
11
- FIRST_DATA_LINE_NUMBER = 10
12
-
13
- Logger = logging.getLogger(__name__)
14
-
15
-
16
- # ------------------------------------------------------------------------------------------------------------
17
- class ExcelParser:
18
-
19
- # ------------------------------------------------------
20
- @staticmethod
21
- def parse(dataFilename: str, dataReadingFrequency: Frequency) -> List[Dict[str, Any]]:
22
-
23
- parseByFrequency = {
24
- Frequency.HOURLY: ExcelParser.__parseHourly,
25
- Frequency.DAILY: ExcelParser.__parseDaily,
26
- Frequency.WEEKLY: ExcelParser.__parseWeekly,
27
- Frequency.MONTHLY: ExcelParser.__parseMonthly
28
- }
29
-
30
- Logger.debug(f"Loading Excel data file '{dataFilename}'...")
31
-
32
- workbook = load_workbook(filename=dataFilename)
33
-
34
- worksheet = workbook.active
35
-
36
- res = parseByFrequency[dataReadingFrequency](worksheet) # type: ignore
37
-
38
- workbook.close()
39
-
40
- return res
41
-
42
- # ------------------------------------------------------
43
- @staticmethod
44
- def __fillRow(row: Dict, propertyName: str, cell: Cell, isNumber: bool):
45
-
46
- if cell.value is not None:
47
- if isNumber:
48
- if type(cell.value) is str:
49
- if len(cell.value.strip()) > 0:
50
- row[propertyName] = float(cell.value.replace(',', '.'))
51
- else:
52
- row[propertyName] = cell.value
53
- else:
54
- row[propertyName] = cell.value.strip() if type(cell.value) is str else cell.value
55
-
56
- # ------------------------------------------------------
57
- @staticmethod
58
- def __parseHourly(worksheet: Worksheet) -> List[Dict[str, Any]]:
59
- return []
60
-
61
- # ------------------------------------------------------
62
- @staticmethod
63
- def __parseDaily(worksheet: Worksheet) -> List[Dict[str, Any]]:
64
-
65
- res = []
66
-
67
- # Timestamp of the data.
68
- data_timestamp = datetime.now().isoformat()
69
-
70
- minRowNum = FIRST_DATA_LINE_NUMBER
71
- maxRowNum = len(worksheet['B'])
72
- for rownum in range(minRowNum, maxRowNum + 1):
73
- row = {}
74
- if worksheet.cell(column=2, row=rownum).value is not None:
75
- ExcelParser.__fillRow(row, PropertyName.TIME_PERIOD.value, worksheet.cell(column=2, row=rownum), False) # type: ignore
76
- ExcelParser.__fillRow(row, PropertyName.START_INDEX.value, worksheet.cell(column=3, row=rownum), True) # type: ignore
77
- ExcelParser.__fillRow(row, PropertyName.END_INDEX.value, worksheet.cell(column=4, row=rownum), True) # type: ignore
78
- ExcelParser.__fillRow(row, PropertyName.VOLUME.value, worksheet.cell(column=5, row=rownum), True) # type: ignore
79
- ExcelParser.__fillRow(row, PropertyName.ENERGY.value, worksheet.cell(column=6, row=rownum), True) # type: ignore
80
- ExcelParser.__fillRow(row, PropertyName.CONVERTER_FACTOR.value, worksheet.cell(column=7, row=rownum), True) # type: ignore
81
- ExcelParser.__fillRow(row, PropertyName.TEMPERATURE.value, worksheet.cell(column=8, row=rownum), True) # type: ignore
82
- ExcelParser.__fillRow(row, PropertyName.TYPE.value, worksheet.cell(column=9, row=rownum), False) # type: ignore
83
- row[PropertyName.TIMESTAMP.value] = data_timestamp
84
- res.append(row)
85
-
86
- Logger.debug(f"Daily data read successfully between row #{minRowNum} and row #{maxRowNum}")
87
-
88
- return res
89
-
90
- # ------------------------------------------------------
91
- @staticmethod
92
- def __parseWeekly(worksheet: Worksheet) -> List[Dict[str, Any]]:
93
-
94
- res = []
95
-
96
- # Timestamp of the data.
97
- data_timestamp = datetime.now().isoformat()
98
-
99
- minRowNum = FIRST_DATA_LINE_NUMBER
100
- maxRowNum = len(worksheet['B'])
101
- for rownum in range(minRowNum, maxRowNum + 1):
102
- row = {}
103
- if worksheet.cell(column=2, row=rownum).value is not None:
104
- ExcelParser.__fillRow(row, PropertyName.TIME_PERIOD.value, worksheet.cell(column=2, row=rownum), False) # type: ignore
105
- ExcelParser.__fillRow(row, PropertyName.VOLUME.value, worksheet.cell(column=3, row=rownum), True) # type: ignore
106
- ExcelParser.__fillRow(row, PropertyName.ENERGY.value, worksheet.cell(column=4, row=rownum), True) # type: ignore
107
- row[PropertyName.TIMESTAMP.value] = data_timestamp
108
- res.append(row)
109
-
110
- Logger.debug(f"Weekly data read successfully between row #{minRowNum} and row #{maxRowNum}")
111
-
112
- return res
113
-
114
- # ------------------------------------------------------
115
- @staticmethod
116
- def __parseMonthly(worksheet: Worksheet) -> List[Dict[str, Any]]:
117
-
118
- res = []
119
-
120
- # Timestamp of the data.
121
- data_timestamp = datetime.now().isoformat()
122
-
123
- minRowNum = FIRST_DATA_LINE_NUMBER
124
- maxRowNum = len(worksheet['B'])
125
- for rownum in range(minRowNum, maxRowNum + 1):
126
- row = {}
127
- if worksheet.cell(column=2, row=rownum).value is not None:
128
- ExcelParser.__fillRow(row, PropertyName.TIME_PERIOD.value, worksheet.cell(column=2, row=rownum), False) # type: ignore
129
- ExcelParser.__fillRow(row, PropertyName.VOLUME.value, worksheet.cell(column=3, row=rownum), True) # type: ignore
130
- ExcelParser.__fillRow(row, PropertyName.ENERGY.value, worksheet.cell(column=4, row=rownum), True) # type: ignore
131
- row[PropertyName.TIMESTAMP.value] = data_timestamp
132
- res.append(row)
133
-
134
- Logger.debug(f"Monthly data read successfully between row #{minRowNum} and row #{maxRowNum}")
135
-
136
- return res
1
+ import logging
2
+ from datetime import datetime
3
+ from pygazpar.enum import Frequency
4
+ from pygazpar.enum import PropertyName
5
+ from openpyxl.worksheet.worksheet import Worksheet
6
+ from openpyxl.cell.cell import Cell
7
+ from openpyxl import load_workbook
8
+ from typing import Any, List, Dict
9
+
10
+
11
+ FIRST_DATA_LINE_NUMBER = 10
12
+
13
+ Logger = logging.getLogger(__name__)
14
+
15
+
16
+ # ------------------------------------------------------------------------------------------------------------
17
+ class ExcelParser:
18
+
19
+ # ------------------------------------------------------
20
+ @staticmethod
21
+ def parse(dataFilename: str, dataReadingFrequency: Frequency) -> List[Dict[str, Any]]:
22
+
23
+ parseByFrequency = {
24
+ Frequency.HOURLY: ExcelParser.__parseHourly,
25
+ Frequency.DAILY: ExcelParser.__parseDaily,
26
+ Frequency.WEEKLY: ExcelParser.__parseWeekly,
27
+ Frequency.MONTHLY: ExcelParser.__parseMonthly
28
+ }
29
+
30
+ Logger.debug(f"Loading Excel data file '{dataFilename}'...")
31
+
32
+ workbook = load_workbook(filename=dataFilename)
33
+
34
+ worksheet = workbook.active
35
+
36
+ res = parseByFrequency[dataReadingFrequency](worksheet) # type: ignore
37
+
38
+ workbook.close()
39
+
40
+ Logger.debug("Processed Excel %s data: %s", dataReadingFrequency, res)
41
+
42
+ return res
43
+
44
+ # ------------------------------------------------------
45
+ @staticmethod
46
+ def __fillRow(row: Dict, propertyName: str, cell: Cell, isNumber: bool):
47
+
48
+ if cell.value is not None:
49
+ if isNumber:
50
+ if type(cell.value) is str:
51
+ if len(cell.value.strip()) > 0:
52
+ row[propertyName] = float(cell.value.replace(',', '.'))
53
+ else:
54
+ row[propertyName] = cell.value
55
+ else:
56
+ row[propertyName] = cell.value.strip() if type(cell.value) is str else cell.value
57
+
58
+ # ------------------------------------------------------
59
+ @staticmethod
60
+ def __parseHourly(worksheet: Worksheet) -> List[Dict[str, Any]]:
61
+ return []
62
+
63
+ # ------------------------------------------------------
64
+ @staticmethod
65
+ def __parseDaily(worksheet: Worksheet) -> List[Dict[str, Any]]:
66
+
67
+ res = []
68
+
69
+ # Timestamp of the data.
70
+ data_timestamp = datetime.now().isoformat()
71
+
72
+ minRowNum = FIRST_DATA_LINE_NUMBER
73
+ maxRowNum = len(worksheet['B'])
74
+ for rownum in range(minRowNum, maxRowNum + 1):
75
+ row = {}
76
+ if worksheet.cell(column=2, row=rownum).value is not None:
77
+ ExcelParser.__fillRow(row, PropertyName.TIME_PERIOD.value, worksheet.cell(column=2, row=rownum), False) # type: ignore
78
+ ExcelParser.__fillRow(row, PropertyName.START_INDEX.value, worksheet.cell(column=3, row=rownum), True) # type: ignore
79
+ ExcelParser.__fillRow(row, PropertyName.END_INDEX.value, worksheet.cell(column=4, row=rownum), True) # type: ignore
80
+ ExcelParser.__fillRow(row, PropertyName.VOLUME.value, worksheet.cell(column=5, row=rownum), True) # type: ignore
81
+ ExcelParser.__fillRow(row, PropertyName.ENERGY.value, worksheet.cell(column=6, row=rownum), True) # type: ignore
82
+ ExcelParser.__fillRow(row, PropertyName.CONVERTER_FACTOR.value, worksheet.cell(column=7, row=rownum), True) # type: ignore
83
+ ExcelParser.__fillRow(row, PropertyName.TEMPERATURE.value, worksheet.cell(column=8, row=rownum), True) # type: ignore
84
+ ExcelParser.__fillRow(row, PropertyName.TYPE.value, worksheet.cell(column=9, row=rownum), False) # type: ignore
85
+ row[PropertyName.TIMESTAMP.value] = data_timestamp
86
+ res.append(row)
87
+
88
+ Logger.debug(f"Daily data read successfully between row #{minRowNum} and row #{maxRowNum}")
89
+
90
+ return res
91
+
92
+ # ------------------------------------------------------
93
+ @staticmethod
94
+ def __parseWeekly(worksheet: Worksheet) -> List[Dict[str, Any]]:
95
+
96
+ res = []
97
+
98
+ # Timestamp of the data.
99
+ data_timestamp = datetime.now().isoformat()
100
+
101
+ minRowNum = FIRST_DATA_LINE_NUMBER
102
+ maxRowNum = len(worksheet['B'])
103
+ for rownum in range(minRowNum, maxRowNum + 1):
104
+ row = {}
105
+ if worksheet.cell(column=2, row=rownum).value is not None:
106
+ ExcelParser.__fillRow(row, PropertyName.TIME_PERIOD.value, worksheet.cell(column=2, row=rownum), False) # type: ignore
107
+ ExcelParser.__fillRow(row, PropertyName.VOLUME.value, worksheet.cell(column=3, row=rownum), True) # type: ignore
108
+ ExcelParser.__fillRow(row, PropertyName.ENERGY.value, worksheet.cell(column=4, row=rownum), True) # type: ignore
109
+ row[PropertyName.TIMESTAMP.value] = data_timestamp
110
+ res.append(row)
111
+
112
+ Logger.debug(f"Weekly data read successfully between row #{minRowNum} and row #{maxRowNum}")
113
+
114
+ return res
115
+
116
+ # ------------------------------------------------------
117
+ @staticmethod
118
+ def __parseMonthly(worksheet: Worksheet) -> List[Dict[str, Any]]:
119
+
120
+ res = []
121
+
122
+ # Timestamp of the data.
123
+ data_timestamp = datetime.now().isoformat()
124
+
125
+ minRowNum = FIRST_DATA_LINE_NUMBER
126
+ maxRowNum = len(worksheet['B'])
127
+ for rownum in range(minRowNum, maxRowNum + 1):
128
+ row = {}
129
+ if worksheet.cell(column=2, row=rownum).value is not None:
130
+ ExcelParser.__fillRow(row, PropertyName.TIME_PERIOD.value, worksheet.cell(column=2, row=rownum), False) # type: ignore
131
+ ExcelParser.__fillRow(row, PropertyName.VOLUME.value, worksheet.cell(column=3, row=rownum), True) # type: ignore
132
+ ExcelParser.__fillRow(row, PropertyName.ENERGY.value, worksheet.cell(column=4, row=rownum), True) # type: ignore
133
+ row[PropertyName.TIMESTAMP.value] = data_timestamp
134
+ res.append(row)
135
+
136
+ Logger.debug(f"Monthly data read successfully between row #{minRowNum} and row #{maxRowNum}")
137
+
138
+ return res
pygazpar/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "1.2.7"
1
+ __version__ = "1.2.8"
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: pygazpar
3
- Version: 1.2.7
3
+ Version: 1.2.8
4
4
  Summary: Retrieve gas consumption from GrDF web site (French Gas Company)
5
5
  Home-page: https://github.com/ssenart/pygazpar
6
6
  Download-URL: https://github.com/ssenart/pygazpar/releases
@@ -17,18 +17,18 @@ Platform: any
17
17
  Classifier: Development Status :: 5 - Production/Stable
18
18
  Classifier: Topic :: Software Development :: Libraries
19
19
  Classifier: Operating System :: OS Independent
20
- Classifier: Programming Language :: Python :: 3.7
21
- Classifier: Programming Language :: Python :: 3.8
22
20
  Classifier: Programming Language :: Python :: 3.9
23
21
  Classifier: Programming Language :: Python :: 3.10
24
22
  Classifier: Programming Language :: Python :: 3.11
25
23
  Classifier: Programming Language :: Python :: 3.12
26
- Requires-Python: >=3.7
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Requires-Python: >=3.9
27
26
  Description-Content-Type: text/markdown
28
27
  License-File: LICENSE.md
29
28
  Requires-Dist: openpyxl>=2.6.3
30
29
  Requires-Dist: requests>=2.26.0
31
30
  Requires-Dist: pandas
31
+ Dynamic: download-url
32
32
 
33
33
  # PyGazpar
34
34
 
@@ -218,6 +218,11 @@ All notable changes to this project will be documented in this file.
218
218
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
219
219
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
220
220
 
221
+ ## [1.2.8](https://github.com/ssenart/PyGazpar/compare/1.2.8...1.2.7) - 2025-01-11
222
+
223
+ ### Added
224
+ - [#81](https://github.com/ssenart/PyGazpar/issues/81): Add meter/temperature debug log messages to help investigation in case of errors.
225
+
221
226
  ## [1.2.7](https://github.com/ssenart/PyGazpar/compare/1.2.7...1.2.6) - 2025-01-06
222
227
 
223
228
  ### 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=D6VBy4ngQDECQfPVi9ZGhKuuOxNDUHjK-9gTDJlATPI,20699
4
+ pygazpar/datasource.py,sha256=SQ6ko4ElWp9BBid-TcBo9iWiCMO4VL-_pTkGb6sCGDE,21400
5
5
  pygazpar/enum.py,sha256=3ZCk4SziXF6pxgP3MuQ1qxYfqB3X5DOV8Rtd0GHsK9w,898
6
- pygazpar/excelparser.py,sha256=QNFIErXNgMjGGjsGjdnRxAbNpfVagdYmZQtXRub3_Xc,5931
6
+ pygazpar/excelparser.py,sha256=A9s0A1xpIxGiqLvVd80p7ntb89Grq9-tVb46Al0xJx8,6149
7
7
  pygazpar/jsonparser.py,sha256=OrRdMZNBi7rI4dRGoRW7gjyFwJFk-IvtkRZ_t1XVFrI,1859
8
- pygazpar/version.py,sha256=49prCLbE3fFzLfxem5rd2dr1iV4_L-bN0N4J7jxU5yA,22
8
+ pygazpar/version.py,sha256=CfVXm0wwlKPW0khOcwhWw61TpgtZiLijCePsAIOK3aU,22
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
@@ -19,9 +19,9 @@ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  tests/test_client.py,sha256=BFLz0GNk8qEP4d2-7cAaIcLWpkSnDZo3wRb0AlXBNOQ,5765
20
20
  tests/test_datafileparser.py,sha256=nAeUpOHtelblMpmbrrnf-2GuMjK5ai65veDoymceprE,818
21
21
  tests/test_datasource.py,sha256=NTeD3yQEi4fTw8ZWz2cuUUdeFC8QVjChBMw5jyqia40,6149
22
- pygazpar-1.2.7.dist-info/LICENSE.md,sha256=XsCJx_7_BC9tvmE0ZxS1cTNR7ekurog_ea9ybdZ-8tc,1073
23
- pygazpar-1.2.7.dist-info/METADATA,sha256=VULYhqTVeudSeCcyBxU_jg4un4FdS7N7ydLHc7cwtr8,19249
24
- pygazpar-1.2.7.dist-info/WHEEL,sha256=f6NuRykhyx7vCtlEy-mvf2B8vPSsWyYD7mCW_EY45Cc,93
25
- pygazpar-1.2.7.dist-info/entry_points.txt,sha256=dNJjC6RYY3FeJIe0hZL9Kcr6vKEx1qkZ71e6Slocb7I,52
26
- pygazpar-1.2.7.dist-info/top_level.txt,sha256=P7qn-XtanDPBLQsTvjvLV71wH8RK0DYbx8tzN_rDS70,23
27
- pygazpar-1.2.7.dist-info/RECORD,,
22
+ pygazpar-1.2.8.dist-info/LICENSE.md,sha256=XsCJx_7_BC9tvmE0ZxS1cTNR7ekurog_ea9ybdZ-8tc,1073
23
+ pygazpar-1.2.8.dist-info/METADATA,sha256=sl9nqURRaGEYNeNWnu7_izw5h2at-COvx85heMYb-ps,19455
24
+ pygazpar-1.2.8.dist-info/WHEEL,sha256=f-tFxHoSaKxpBvh-cZLVJ_1-woq1R_qTNWIS7rvXlLs,93
25
+ pygazpar-1.2.8.dist-info/entry_points.txt,sha256=dNJjC6RYY3FeJIe0hZL9Kcr6vKEx1qkZ71e6Slocb7I,52
26
+ pygazpar-1.2.8.dist-info/top_level.txt,sha256=P7qn-XtanDPBLQsTvjvLV71wH8RK0DYbx8tzN_rDS70,23
27
+ pygazpar-1.2.8.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.7.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py312-none-any
5
5