add book wishlist work adding

This commit is contained in:
Ben Goldsworthy 2024-02-15 11:28:11 +00:00
parent b5bbe3ae08
commit 34885d4cda
2 changed files with 45 additions and 9 deletions

View file

@ -1,4 +1,30 @@
[ [
{
"id": "OL27719403W",
"title": "The hidden life of trees",
"subjects": [
"Trees",
"Ecology",
"Forest ecology",
"Wald\u00f6kosystem"
]
},
{
"id": "OL25815646W",
"title": "An Immense World",
"subjects": [
"nyt:combined-print-and-e-book-nonfiction=2022-07-10",
"New York Times bestseller",
"Senses and sensation",
"Animal behavior",
"Physiology",
"Neurosciences",
"Sensation",
"Sens et sensations",
"Physiologie",
"nyt:paperback-nonfiction=2023-09-17"
]
},
{ {
"id": "OL21164374W", "id": "OL21164374W",
"title": "Tender is the Flesh", "title": "Tender is the Flesh",
@ -89303,4 +89329,4 @@
], ],
"date_added": "2013-05-07" "date_added": "2013-05-07"
} }
] ]

View file

@ -126,11 +126,11 @@ def add_item_to_log(item_id, media_type, log) -> None:
item = None item = None
log_to_delete = None log_to_delete = None
if "tv-episodes" != media_type: if "tv-episodes" != media_type and ("books" != media_type and "wishlist" != log):
item, log_to_delete = check_for_existing(item_id, media_type, log) item, log_to_delete = check_for_existing(item_id, media_type, log)
if item is None: if item is None:
item = import_by_id(item_id, media_type) item = import_by_id(item_id, media_type, log)
if item is None: if item is None:
raise Exception("No item found") raise Exception("No item found")
@ -189,7 +189,7 @@ def add_item_to_log(item_id, media_type, log) -> None:
delete_existing(item_id, media_type, log_to_delete) delete_existing(item_id, media_type, log_to_delete)
def import_by_id(import_id, media_type) -> dict: def import_by_id(import_id, media_type, log) -> dict:
"""Import from the appropriate API by unique ID""" """Import from the appropriate API by unique ID"""
if media_type in ["films", "tv-series"]: if media_type in ["films", "tv-series"]:
@ -199,9 +199,13 @@ def import_by_id(import_id, media_type) -> dict:
return import_from_tmdb_by_imdb_id(import_id, media_type) return import_from_tmdb_by_imdb_id(import_id, media_type)
if media_type in ["books"]: if media_type in ["books"]:
return import_from_openlibrary_by_id( if "wishlist" == log:
"".join(re.findall(r"\d+", import_id)), media_type return import_from_openlibrary_by_ol_key(import_id)
)
else:
return import_from_openlibrary_by_id(
"".join(re.findall(r"\d+", import_id)), media_type
)
def import_from_tmdb_by_imdb_id(imdb_id, media_type) -> dict: def import_from_tmdb_by_imdb_id(imdb_id, media_type) -> dict:
@ -326,6 +330,9 @@ def import_from_openlibrary_by_id(isbn, media_type) -> dict:
def import_from_openlibrary_by_ol_key(key) -> dict: def import_from_openlibrary_by_ol_key(key) -> dict:
"""Retrieves an item (author or work, NOT edition) from OpenLibrary using an OL key""" """Retrieves an item (author or work, NOT edition) from OpenLibrary using an OL key"""
if (len(key.split("/")) == 1):
key = f"/works/{key}"
logger.info(f"Retrieving {key}") logger.info(f"Retrieving {key}")
_, mode, ol_id = key.split("/") _, mode, ol_id = key.split("/")
@ -533,12 +540,15 @@ def main() -> None:
log = input("Enter log to update [log|current|wishlist]: ") log = input("Enter log to update [log|current|wishlist]: ")
while re.search("[0-9]+", item_id) is None: while re.search("[0-9]+", item_id) is None:
item_id = "".join(re.findall(r"\d+", input("Enter ISBN: "))) if "wishlist" == log:
item_id = input("Enter OpenLibrary Work ID: ")
else:
item_id = "".join(re.findall(r"\d+", input("Enter ISBN: ")))
elif "tv-episodes" == media_type: elif "tv-episodes" == media_type:
log = "log" log = "log"
while re.search("[0-9]+", item_id) is None: while re.search("[0-9]+", item_id) is None:
item_id = input("Enter TVDB ID: ") item_id = input("Enter IMDB ID: ")
elif "tv-series" == media_type: elif "tv-series" == media_type:
log = "" log = ""