mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-28 11:00:36 +00:00
Process dates in librarything import
This commit is contained in:
parent
20baf9385d
commit
4d574a3536
2 changed files with 10 additions and 0 deletions
|
@ -35,6 +35,7 @@ class Importer:
|
||||||
"date_started": ["date started", "started"],
|
"date_started": ["date started", "started"],
|
||||||
"date_finished": ["date finished", "last date read", "date read", "finished"],
|
"date_finished": ["date finished", "last date read", "date read", "finished"],
|
||||||
}
|
}
|
||||||
|
date_fields = ["date_added", "date_started", "date_finished"]
|
||||||
|
|
||||||
def create_job(self, user, csv_file, include_reviews, privacy):
|
def create_job(self, user, csv_file, include_reviews, privacy):
|
||||||
"""check over a csv and creates a database entry for the job"""
|
"""check over a csv and creates a database entry for the job"""
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
""" handle reading a tsv from librarything """
|
""" handle reading a tsv from librarything """
|
||||||
|
import re
|
||||||
from . import Importer
|
from . import Importer
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,3 +9,11 @@ class LibrarythingImporter(Importer):
|
||||||
service = "LibraryThing"
|
service = "LibraryThing"
|
||||||
delimiter = "\t"
|
delimiter = "\t"
|
||||||
encoding = "ISO-8859-1"
|
encoding = "ISO-8859-1"
|
||||||
|
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in a new issue