2021-05-10 17:00:51 +00:00
|
|
|
""" handle reading a csv from librarything """
|
|
|
|
import re
|
|
|
|
|
|
|
|
from . import Importer
|
|
|
|
|
|
|
|
|
|
|
|
class StorygraphImporter(Importer):
|
|
|
|
"""csv downloads from librarything"""
|
|
|
|
|
|
|
|
service = "Storygraph"
|
|
|
|
# mandatory_fields : fields matching the book title and author
|
2021-05-10 23:11:44 +00:00
|
|
|
mandatory_fields = ["Title"]
|
2021-05-10 17:00:51 +00:00
|
|
|
|
|
|
|
def parse_fields(self, entry):
|
|
|
|
"""custom parsing for storygraph"""
|
|
|
|
data = {}
|
|
|
|
data["import_source"] = self.service
|
|
|
|
data["Title"] = entry["Title"]
|
2021-05-10 23:11:44 +00:00
|
|
|
data["Author"] = entry["Authors"] if "Authors" in entry else entry["Author"]
|
2021-05-10 17:00:51 +00:00
|
|
|
data["ISBN13"] = entry["ISBN"]
|
|
|
|
data["My Review"] = entry["Review"]
|
|
|
|
if entry["Star Rating"]:
|
2021-11-10 17:53:52 +00:00
|
|
|
data["My Rating"] = float(entry["Star Rating"])
|
2021-05-10 17:00:51 +00:00
|
|
|
else:
|
|
|
|
data["My Rating"] = ""
|
|
|
|
|
|
|
|
data["Date Added"] = re.sub(r"[/]", "-", entry["Date Added"])
|
|
|
|
data["Date Read"] = re.sub(r"[/]", "-", entry["Last Date Read"])
|
|
|
|
|
2021-05-10 18:56:35 +00:00
|
|
|
data["Exclusive Shelf"] = (
|
|
|
|
{"read": "read", "currently-reading": "reading", "to-read": "to-read"}
|
|
|
|
).get(entry["Read Status"], None)
|
2021-05-10 17:00:51 +00:00
|
|
|
return data
|