moviewyrm/bookwyrm/importers/storygraph_import.py

35 lines
1.1 KiB
Python
Raw Normal View History

2021-05-10 17:00:51 +00:00
""" handle reading a csv from librarything """
import re
import math
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"]:
data["My Rating"] = math.ceil(float(entry["Star Rating"]))
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