Strip initials from koreader authors

This commit is contained in:
2023-03-27 01:33:30 -04:00
parent ee01ffa4ad
commit cb0c00a695
2 changed files with 4 additions and 6 deletions

View File

@ -1,3 +1,4 @@
import re
import codecs
import logging
import os
@ -69,6 +70,8 @@ def get_book_map_from_sqlite(rows: Iterable) -> dict:
ko_authors = book_row[
KoReaderBookColumn.AUTHORS.value
].replace("\n", ", ")
# Strip middle initials, OpenLibrary often fails with these
ko_authors = re.sub(" [A-Z]. ", " ", ko_authors)
book_dict = {
"title": book_row[KoReaderBookColumn.TITLE.value],
"pages": total_pages,
@ -80,9 +83,7 @@ def get_book_map_from_sqlite(rows: Iterable) -> dict:
Book.objects.filter(pk=book.id).update(**book_dict)
# Add authors
authors = book_row[KoReaderBookColumn.AUTHORS.value].split(
"\n"
)
authors = ko_authors.split(", ")
author_list = []
for author_str in authors:
logger.debug(f"Looking up author {author_str}")

View File

@ -1,6 +1,5 @@
import json
import logging
import re
import urllib
import requests
@ -79,8 +78,6 @@ def lookup_book_from_openlibrary(title: str, author: str = None) -> dict:
title_quoted = urllib.parse.quote(title)
author_quoted = ""
if author:
# Strip middle initials, OpenLibrary often fails with these
author = re.sub(" [A-Z]. ", " ", author)
author_quoted = urllib.parse.quote(author)
query = f"{title_quoted} {author_quoted}"