2021-11-11 00:49:54 +00:00
|
|
|
""" 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"""
|
2021-11-13 20:46:27 +00:00
|
|
|
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()}
|
2021-12-28 23:22:20 +00:00
|
|
|
isbn_13 = normalized.get("isbn_13")
|
|
|
|
isbn_13 = isbn_13.split(", ") if isbn_13 else []
|
2021-11-13 20:46:27 +00:00
|
|
|
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"
|