Skip to content

Commit

Permalink
Merge pull request #1 from larsalthof/patch-1
Browse files Browse the repository at this point in the history
Update library_api.py, 3 changes: Update name of userID field, add expected date for eloans, change handling of http errors
  • Loading branch information
larsalthof authored Feb 2, 2024
2 parents 6036c50 + 8058487 commit ec8a046
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions custom_components/bibliotek_dk/library_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,18 @@ def _fetchPage(self, url=str, payload=None, return_r=False) -> BS | tuple:
r.raise_for_status()

except requests.exceptions.HTTPError as err:
raise SystemExit(err) from err
_LOGGER.error(f"HTTP Error while fetching {url}: {err}")
# Handle the error as needed, e.g., raise it, log it, or notify the user.
return None if return_r else None, None
except requests.exceptions.Timeout:
_LOGGER.error("Timeout fecthing (%s)", url)
return None if return_r else None, None
except requests.exceptions.TooManyRedirects:
_LOGGER.error("Too many redirects fecthing (%s)", url)
return None if return_r else None, None
except requests.exceptions.RequestException as err:
raise SystemExit(err) from err
_LOGGER.error(f"Request Exception while fetching {url}: {err}")
return None if return_r else None, None

if return_r:
return BS(r.text, "html.parser"), r
Expand Down Expand Up @@ -518,6 +523,8 @@ def fetchLoans(self, soup=None):
obj.loanDate = self._getDatetime(value)
elif "expire-date" in keys:
obj.expireDate = self._getDatetime(value)
elif "expected-date" in keys:
obj.expireDate = self._getDatetime(value)
elif "material-number" in keys:
obj.id = value

Expand Down Expand Up @@ -671,7 +678,7 @@ class libraryUser:
pickupLibrary = None

def __init__(self, userId: str, pincode: str) -> None:
self.userInfo = {"userId": userId, "pincode": pincode}
self.userInfo = {"loginBibDkUserId": userId, "pincode": pincode}
self.userId = userId


Expand Down

0 comments on commit ec8a046

Please sign in to comment.