moviewyrm/bookwyrm/importers/librarything_import.py

28 lines
956 B
Python
Raw Normal View History

""" handle reading a tsv from librarything """
2021-11-11 17:54:36 +00:00
import re
2021-03-30 15:56:25 +00:00
from . import Importer
2021-02-20 16:02:36 +00:00
class LibrarythingImporter(Importer):
2021-04-26 16:15:42 +00:00
"""csv downloads from librarything"""
2021-03-30 15:43:38 +00:00
2021-03-08 16:49:10 +00:00
service = "LibraryThing"
delimiter = "\t"
encoding = "ISO-8859-1"
2021-11-11 17:54:36 +00:00
def normalize_row(self, entry, mappings): # pylint: disable=no-self-use
"""use the dataclass to create the formatted row of data"""
remove_brackets = lambda v: re.sub(r"\[|\]", "", v) if v else None
2021-11-14 15:11:48 +00:00
normalized = {k: remove_brackets(entry.get(v)) for k, v in mappings.items()}
isbn_13 = normalized.get("isbn_13")
isbn_13 = isbn_13.split(", ") if isbn_13 else []
normalized["isbn_13"] = isbn_13[1] if len(isbn_13) > 0 else None
2021-11-11 17:54:36 +00:00
return normalized
2021-11-11 20:29:38 +00:00
def get_shelf(self, normalized_row):
if normalized_row["date_finished"]:
return "read"
if normalized_row["date_started"]:
return "reading"
return "to-read"