From ca1110360c6120de3d098899f71e2ecc6a52236d Mon Sep 17 00:00:00 2001 From: Ward Van Heddeghem Date: Thu, 28 Dec 2023 19:01:43 +0100 Subject: [PATCH] Raise some log message to info level --- src/mijnbib/mijnbibliotheek.py | 27 ++++++++++++++++----------- src/mijnbib/parsers.py | 1 + 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/mijnbib/mijnbibliotheek.py b/src/mijnbib/mijnbibliotheek.py index f79dc68..1711bab 100644 --- a/src/mijnbib/mijnbibliotheek.py +++ b/src/mijnbib/mijnbibliotheek.py @@ -60,11 +60,12 @@ def login(self) -> None: IncompatibleSourceError """ url = self.BASE_URL + "/mijn-bibliotheek/aanmelden" - _log.debug(f"Will log in at url : {url}") - _log.debug(f" with id : {self._username}") + _log.info(f"Will log in at url : {url}") + _log.info(f" with id : {self._username}") response = self._log_in(url) - self._validate_logged_in(response) # raises AuthenticationError if not ok + html = response.read().decode("utf-8") if response is not None else "" + self._validate_logged_in(html) # raises AuthenticationError if not ok self._logged_in = True @@ -77,6 +78,7 @@ def get_loans(self, account_id: str) -> list[Loan]: ItemAccessError: something went wrong fetching loans TemporarySiteError """ + _log.info(f"Retrieving loans for account: '{account_id}'") if not self._logged_in: self.login() @@ -100,6 +102,7 @@ def get_reservations(self, account_id: str) -> list[Reservation]: IncompatibleSourceError ItemAccessError: something went wrong fetching reservations """ + _log.info(f"Retrieving reservations for account: '{account_id}'") if not self._logged_in: self.login() @@ -120,11 +123,12 @@ def get_accounts(self) -> list[Account]: AuthenticationError IncompatibleSourceError """ + _log.info(f"Retrieving accounts") if not self._logged_in: self.login() url = self.BASE_URL + "/mijn-bibliotheek/lidmaatschappen" - _log.debug("Opening page 'lidmaatschappen' ... ") + _log.debug(f"Opening page '{url}' ... ") response = self._br.open(url) # pylint: disable=assignment-from-none html_string = response.read().decode("utf-8") # type:ignore try: @@ -148,6 +152,7 @@ def get_all_info(self, all_as_dicts=False) -> dict: IncompatibleSourceError ItemAccessError: something went wrong fetching loans or reservations """ + _log.info(f"Retrieving all information") info = {} accounts = self.get_accounts() for a in accounts: @@ -196,7 +201,7 @@ def extend_loans(self, extend_url: str, execute: bool = False) -> tuple[bool, di if not self._logged_in: self.login() - _log.debug(f"Will extend loan via url: {extend_url}") + _log.info(f"Will extend loan via url: {extend_url}") try: response = self._br.open(extend_url) # pylint: disable=assignment-from-none except mechanize.HTTPError as e: @@ -260,6 +265,7 @@ def extend_loans_by_ids( acc_eids: List of (account, extend_id) tuples execute: A development flag; set to True actually perform loan extension """ + _log.info(f"Extending loans via ids: '{acc_extids}'") if not acc_extids: raise ValueError("List must not be empty.") account_id, _extend_id = acc_extids[0] # use first acc id for general account id @@ -298,13 +304,12 @@ def _log_in(self, url): ) from e return response - def _validate_logged_in(self, response): + def _validate_logged_in(self, html: str): _log.debug("Checking if login is successful ...") - html_string = response.read().decode("utf-8") if response is not None else "" - if "Profiel" not in html_string: + if "Profiel" not in html: if ( - "privacyverklaring is gewijzigd" in html_string - or "akkoord met de privacyverklaring" in html_string + "privacyverklaring is gewijzigd" in html + or "akkoord met de privacyverklaring" in html ): raise AuthenticationError( "Login not accepted (likely need to accept privacy statement again)" @@ -314,7 +319,7 @@ def _validate_logged_in(self, response): _log.debug("Login was successful") def _open_account_loans_page(self, acc_url: str) -> str: - _log.debug(f"Opening page ({acc_url}) ... ") + _log.debug(f"Opening page '{acc_url}' ... ") try: response = self._br.open(acc_url) # pylint: disable=assignment-from-none except mechanize.HTTPError as e: diff --git a/src/mijnbib/parsers.py b/src/mijnbib/parsers.py index 9036154..7d446e0 100644 --- a/src/mijnbib/parsers.py +++ b/src/mijnbib/parsers.py @@ -371,6 +371,7 @@ def parse(self) -> list[Account]: open_amounts_url=open_amounts_url, ) accounts.append(account) + _log.debug("Number of accounts found: %s", len(accounts)) return accounts @staticmethod