Skip to content

Commit

Permalink
Clean up todos
Browse files Browse the repository at this point in the history
  • Loading branch information
wvanhed committed Dec 25, 2023
1 parent f0bc4c7 commit 1a1a59b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/mijnbib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
IncompatibleSourceError,
ItemAccessError,
PluginError,
TemporarySiteError,
)
6 changes: 5 additions & 1 deletion src/mijnbib/mijnbibliotheek.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
IncompatibleSourceError,
InvalidExtendLoanURL,
ItemAccessError,
TemporarySiteError,
)

_log = logging.getLogger(__name__)
Expand Down Expand Up @@ -75,6 +76,7 @@ def get_loans(self, account_id: str) -> list[Loan]:
AuthenticationError
IncompatibleSourceError
ItemAccessError: something went wrong fetching loans
TemporarySiteError
"""
if not self._logged_in:
self.login()
Expand All @@ -83,6 +85,8 @@ def get_loans(self, account_id: str) -> list[Loan]:
html_string = self._open_account_loans_page(url)
try:
loans = LoansListPageParser(html_string, self.BASE_URL, account_id).parse()
except TemporarySiteError as e:
raise e
except Exception as e:
raise IncompatibleSourceError(
f"Problem scraping loans ({str(e)})", html_body=""
Expand Down Expand Up @@ -188,7 +192,7 @@ def extend_loans(self, extend_url: str, execute: bool = False) -> tuple[bool, di
InvalidExtendLoanURL
ExtendLoanError
"""
# TODO: would make more sense to return loan list (since final page is loan page)
# NOTE: would make more sense to return loan list (since final page is loan page)
# Perhaps retrieving those loans again, and check extendability would also be good idea.
if not self._logged_in:
self.login()
Expand Down
7 changes: 5 additions & 2 deletions src/mijnbib/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from bs4 import BeautifulSoup

from mijnbib.models import Account, Loan, Reservation
from mijnbib.plugin_errors import TemporarySiteError

_log = logging.getLogger(__name__)

Expand Down Expand Up @@ -110,10 +111,12 @@ def parse(self) -> list[Loan]:
)
# Sometimes, this error is present
if soup.find(string=re.compile(error_msg)) is not None:
# TODO: probably better to thrown an exception instead
_log.warning(
raise TemporarySiteError(
f"Loans or reservations can not be retrieved. Site reports: {error_msg}"
)
# _log.warning(
# f"Loans or reservations can not be retrieved. Site reports: {error_msg}"
# )
return loans

# Unfortunately, the branch names are interwoven siblings of the loans,
Expand Down
4 changes: 4 additions & 0 deletions src/mijnbib/plugin_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ def __init__(self, msg, html_body: str):

class ExtendLoanError(PluginError):
"""Raised when extending loan(s) failed for unclear reasons."""


class TemporarySiteError(PluginError):
"""Raised when the site reports a temporary error."""
1 change: 1 addition & 0 deletions tests/test_mijnbib.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def test_mijnbib_available_imports():
"ExtendLoanError",
"IncompatibleSourceError",
"PluginError",
"TemporarySiteError",
"plugin_errors",
"mijnbibliotheek",
"parsers",
Expand Down

0 comments on commit 1a1a59b

Please sign in to comment.