Skip to content

Commit

Permalink
Put in some debug information to troubleshoot borrow failures
Browse files Browse the repository at this point in the history
  • Loading branch information
ping committed Aug 1, 2023
1 parent ac3e8e1 commit dfb7914
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions calibre-plugin/borrow_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ def __call__(
"Borrowed %s successfully from %s."
% (get_media_title(loan), card["advantageKey"])
)
if "cardId" not in loan:
loan["cardId"] = hold["cardId"]
logger.warning("Loan info returned does not have cardId")
return loan
1 change: 1 addition & 0 deletions calibre-plugin/libby/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def default_headers(self) -> Dict:
"User-Agent": self.user_agent,
"Accept": "application/json",
"Accept-Encoding": "gzip",
"Referer": "https://libbyapp.com/",
"Cache-Control": "no-cache",
"Pragma": "no-cache",
}
Expand Down
15 changes: 13 additions & 2 deletions calibre-plugin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,30 @@ def sync(self, synced_state: Optional[Dict] = None):
self._libraries = synced_state.get("__libraries", [])

def get_card(self, card_id) -> Optional[Dict]:
return next(
card = next(
iter([c for c in self._cards if c["cardId"] == card_id]),
None,
)
if not card:
raise ValueError("Card is unknown: id=%s" % card_id)
return card

def get_website_id(self, card) -> int:
if not card.get("library"):
raise ValueError(
"Card does not have library details: id=%s, advantageKey=%s"
% (card.get("cardId"), card.get("advantageKey"))
)
return int(card.get("library", {}).get("websiteId", "0"))

def get_library(self, website_id: int) -> Optional[Dict]:
return next(
library = next(
iter([lib for lib in self._libraries if lib["websiteId"] == website_id]),
None,
)
if not library:
raise ValueError("Library is unknown: websiteId=%s" % website_id)
return library


LoanMatchCondition = namedtuple(
Expand Down

0 comments on commit dfb7914

Please sign in to comment.