2021-11-10 19:49:54 -05:00
|
|
|
""" handle reading a tsv from librarything """
|
2021-11-11 12:54:36 -05:00
|
|
|
import re
|
2021-03-30 11:56:25 -04:00
|
|
|
from . import Importer
|
2021-02-20 11:02:36 -05:00
|
|
|
|
|
|
|
|
|
|
|
class LibrarythingImporter(Importer):
|
2021-04-26 12:15:42 -04:00
|
|
|
"""csv downloads from librarything"""
|
2021-03-30 11:43:38 -04:00
|
|
|
|
2021-03-08 11:49:10 -05:00
|
|
|
service = "LibraryThing"
|
|
|
|
delimiter = "\t"
|
|
|
|
encoding = "ISO-8859-1"
|
2021-11-11 12:54:36 -05: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 15:29:38 -05:00
|
|
|
|
|
|
|
def get_shelf(self, normalized_row):
|
|
|
|
if normalized_row["date_finished"]:
|
|
|
|
return "read"
|
|
|
|
if normalized_row["date_started"]:
|
|
|
|
return "reading"
|
|
|
|
return "to-read"
|