Skip to content

Commit

Permalink
[#65] PermissionError happens when loading data from Excel file
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane Senart committed May 8, 2024
1 parent baab6d5 commit 227ac40
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.2.2](https://github.com/ssenart/PyGazpar/compare/1.2.1...1.2.2) - 2024-05-08

### Fixed
- [#65](https://github.com/ssenart/PyGazpar/issues/65): [Bug] PermissionError happens when loading data from Excel file.

## [1.2.1](https://github.com/ssenart/PyGazpar/compare/1.2.0...1.2.1) - 2024-05-04

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# PyGazpar

## $\text{\color{red}{!!! This library is broken since CAPTCHA is mandatory on GrDF site !!!}}$
## <span style="color:green">!!! This library is working again. CAPTCHA has been removed !!!</span>

## <span style="color:red">~~!!! This library is broken since CAPTCHA is mandatory on GrDF site !!!~~</span>

PyGazpar is a Python library for getting natural gas consumption from GrDF French provider.

Expand Down
7 changes: 5 additions & 2 deletions pygazpar/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ def _loadFromSession(self, auth_token: str, pceIdentifier: str, startDate: date,
file_list = glob.glob(data_file_path_pattern)
for filename in file_list:
if os.path.isfile(filename):
os.remove(filename)
try:
os.remove(filename)
except PermissionError:
pass

if frequencies is None:
# Transform Enum in List.
Expand Down Expand Up @@ -194,7 +197,7 @@ def _loadFromSession(self, auth_token: str, pceIdentifier: str, startDate: date,
try:
# openpyxl does not close the file properly.
os.remove(filename)
except Exception:
except PermissionError:
pass

# We compute yearly from daily data.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_monthly_jsonweb(self):

data = client.loadSince(self.__pceIdentifier, 365, [Frequency.MONTHLY])

assert (len(data[Frequency.MONTHLY.value]) >= 12 and len(data[Frequency.MONTHLY.value]) <= 13)
assert (len(data[Frequency.MONTHLY.value]) >= 11 and len(data[Frequency.MONTHLY.value]) <= 13)

def test_yearly_jsonweb(self):
client = Client(JsonWebDataSource(self.__username, self.__password))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_jsonweb(self):

assert (len(data[Frequency.WEEKLY.value]) >= 51 and len(data[Frequency.WEEKLY.value]) <= 54)

assert (len(data[Frequency.MONTHLY.value]) >= 12 and len(data[Frequency.MONTHLY.value]) <= 13)
assert (len(data[Frequency.MONTHLY.value]) >= 11 and len(data[Frequency.MONTHLY.value]) <= 13)

assert (len(data[Frequency.YEARLY.value]) == 1)

Expand Down

0 comments on commit 227ac40

Please sign in to comment.