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"""
|
|
|
|
normalized = {k: entry.get(v) for k, v in mappings.items()}
|
|
|
|
for date_field in self.date_fields:
|
|
|
|
date = normalized[date_field]
|
|
|
|
normalized[date_field] = re.sub(r"\[|\]", "", date)
|
|
|
|
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"
|