Strip initials from koreader authors
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
import re
|
||||||
import codecs
|
import codecs
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -69,6 +70,8 @@ def get_book_map_from_sqlite(rows: Iterable) -> dict:
|
|||||||
ko_authors = book_row[
|
ko_authors = book_row[
|
||||||
KoReaderBookColumn.AUTHORS.value
|
KoReaderBookColumn.AUTHORS.value
|
||||||
].replace("\n", ", ")
|
].replace("\n", ", ")
|
||||||
|
# Strip middle initials, OpenLibrary often fails with these
|
||||||
|
ko_authors = re.sub(" [A-Z]. ", " ", ko_authors)
|
||||||
book_dict = {
|
book_dict = {
|
||||||
"title": book_row[KoReaderBookColumn.TITLE.value],
|
"title": book_row[KoReaderBookColumn.TITLE.value],
|
||||||
"pages": total_pages,
|
"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)
|
Book.objects.filter(pk=book.id).update(**book_dict)
|
||||||
|
|
||||||
# Add authors
|
# Add authors
|
||||||
authors = book_row[KoReaderBookColumn.AUTHORS.value].split(
|
authors = ko_authors.split(", ")
|
||||||
"\n"
|
|
||||||
)
|
|
||||||
author_list = []
|
author_list = []
|
||||||
for author_str in authors:
|
for author_str in authors:
|
||||||
logger.debug(f"Looking up author {author_str}")
|
logger.debug(f"Looking up author {author_str}")
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import re
|
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@ -79,8 +78,6 @@ def lookup_book_from_openlibrary(title: str, author: str = None) -> dict:
|
|||||||
title_quoted = urllib.parse.quote(title)
|
title_quoted = urllib.parse.quote(title)
|
||||||
author_quoted = ""
|
author_quoted = ""
|
||||||
if author:
|
if author:
|
||||||
# Strip middle initials, OpenLibrary often fails with these
|
|
||||||
author = re.sub(" [A-Z]. ", " ", author)
|
|
||||||
author_quoted = urllib.parse.quote(author)
|
author_quoted = urllib.parse.quote(author)
|
||||||
query = f"{title_quoted} {author_quoted}"
|
query = f"{title_quoted} {author_quoted}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user