fix book work importing
This commit is contained in:
parent
b4d528533c
commit
1d6374010d
2 changed files with 14 additions and 6 deletions
|
@ -64,7 +64,7 @@ def return_if_exists(item_id, media_type, log) -> dict | None:
|
|||
existing_items = [
|
||||
log_item
|
||||
for log_item in log_items
|
||||
if "id" in log_item and log_item["id"] == int(item_id)
|
||||
if "id" in log_item and log_item["id"] == item_id
|
||||
]
|
||||
if len(existing_items) > 0:
|
||||
logger.info(f"Found item in '{log}'")
|
||||
|
@ -83,7 +83,7 @@ def delete_existing(item_id, media_type, log) -> None:
|
|||
log_items = [
|
||||
log_item
|
||||
for log_item in log_items
|
||||
if "id" not in log_item or ("id" in log_item and log_item["id"] != int(item_id))
|
||||
if "id" not in log_item or ("id" in log_item and log_item["id"] != item_id)
|
||||
]
|
||||
if len(log_items) < (old_len - 1):
|
||||
raise Exception("More than one deletion made, discarding…")
|
||||
|
@ -355,7 +355,7 @@ def import_from_openlibrary_by_ol_key(key) -> dict:
|
|||
if mode in ["works", "authors"]:
|
||||
if "authors" == mode:
|
||||
matched_cached_authors = [
|
||||
aut for aut in cached_authors if aut["id"] == ol_id
|
||||
aut for aut in cached_authors if aut["ol_id"] == ol_id
|
||||
]
|
||||
if len(matched_cached_authors) == 1:
|
||||
logging.info(
|
||||
|
@ -388,7 +388,7 @@ def import_from_openlibrary_by_ol_key(key) -> dict:
|
|||
|
||||
if "authors" == mode:
|
||||
author = {"ol_id": ol_id, "name": item["name"]}
|
||||
|
||||
print(author)
|
||||
if "personal_name" in item:
|
||||
if item["name"] != item["personal_name"]:
|
||||
author["personal_name"] = item["personal_name"]
|
||||
|
@ -404,12 +404,18 @@ def import_from_openlibrary_by_ol_key(key) -> dict:
|
|||
return author
|
||||
|
||||
if "works" == mode:
|
||||
work = {"ol_id": ol_id, "title": item["title"]}
|
||||
work = {"ol_id": ol_id, "title": item["title"], "authors": []}
|
||||
|
||||
if "authors" in item:
|
||||
for author in item["authors"]:
|
||||
work["authors"].append(import_from_openlibrary_by_ol_key(author["author"]["key"]))
|
||||
|
||||
for result_key in ["first_publish_date", "subjects"]:
|
||||
if result_key in item:
|
||||
work[result_key] = item[result_key]
|
||||
|
||||
work["date_added"] = datetime.today().strftime("%Y-%m-%d")
|
||||
|
||||
return work
|
||||
|
||||
else:
|
||||
|
@ -572,7 +578,7 @@ def main() -> None:
|
|||
while re.search("[0-9]+", item_id) is None:
|
||||
item_id = input("Enter TMDB ID: ")
|
||||
|
||||
add_item_to_log(re.search("(tt)?[0-9]+", item_id)[0], media_type, log)
|
||||
add_item_to_log(re.search("(OL|tt)?[0-9]+[WMA]?", item_id)[0], media_type, log)
|
||||
|
||||
except Exception:
|
||||
logger.exception("Exception occurred")
|
||||
|
|
|
@ -141,6 +141,8 @@ def process_log(media_type, log) -> None:
|
|||
try:
|
||||
new_log_item = import_by_id(ol_work_id[0], media_type, log)
|
||||
except:
|
||||
new_log_item = item
|
||||
item["skip"] = True
|
||||
logger.info("Skipping…")
|
||||
|
||||
elif "ISBN13" in item and item["ISBN13"] != "" and item["ISBN13"] is not None:
|
||||
|
|
Loading…
Reference in a new issue