From 5bac2211fe0ba467065024af98d1f5e61699702f Mon Sep 17 00:00:00 2001 From: Ben Goldsworthy Date: Sun, 17 Mar 2024 13:54:15 +0000 Subject: [PATCH] fix: check for existing items --- scripts/add_item.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/scripts/add_item.py b/scripts/add_item.py index 2b2ba09..92c2bd3 100644 --- a/scripts/add_item.py +++ b/scripts/add_item.py @@ -178,19 +178,28 @@ def add_item_to_log(item_id: str, media_type: str, log: str) -> None: raise Exception("No item found") if "books" == media_type: - new_item, log_to_delete = check_for_existing( - item["work"]["ol_id"], media_type, log - ) + new_item = None + if "work" in "ol_id": + new_item, log_to_delete = check_for_existing( + item["work"]["ol_id"], media_type, log + ) + if new_item is None: - new_item, log_to_delete = check_for_existing(item["ol_id"], media_type, log) + if "ol_id" in item: + new_item, log_to_delete = check_for_existing(item["ol_id"], media_type, log) + if new_item is None: - new_item, log_to_delete = check_for_existing( - item["isbn_13"], media_type, log - ) - if new_item is None: + if "isbn_13" in item: new_item, log_to_delete = check_for_existing( - item["isbn_10"], media_type, log + item["isbn_13"], media_type, log ) + + if new_item is None: + if "isbn_10" in item: + new_item, log_to_delete = check_for_existing( + item["isbn_10"], media_type, log + ) + item = new_item if new_item is not None else item if log in ["log", "current"]: