mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-29 04:51:11 +00:00
Uses general names for fields in parsed csvs
This commit is contained in:
parent
cf477a03ae
commit
0736c7e160
1 changed files with 18 additions and 26 deletions
|
@ -10,14 +10,6 @@ from bookwyrm.models import ReadThrough, User, Book
|
||||||
from .fields import PrivacyLevels
|
from .fields import PrivacyLevels
|
||||||
|
|
||||||
|
|
||||||
# Mapping goodreads -> bookwyrm shelf titles.
|
|
||||||
GOODREADS_SHELVES = {
|
|
||||||
"read": "read",
|
|
||||||
"currently-reading": "reading",
|
|
||||||
"to-read": "to-read",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def unquote_string(text):
|
def unquote_string(text):
|
||||||
"""resolve csv quote weirdness"""
|
"""resolve csv quote weirdness"""
|
||||||
match = re.match(r'="([^"]*)"', text)
|
match = re.match(r'="([^"]*)"', text)
|
||||||
|
@ -106,56 +98,56 @@ class ImportItem(models.Model):
|
||||||
@property
|
@property
|
||||||
def title(self):
|
def title(self):
|
||||||
"""get the book title"""
|
"""get the book title"""
|
||||||
return self.data["Title"]
|
return self.data["title"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def author(self):
|
def author(self):
|
||||||
"""get the book title"""
|
"""get the book's authors"""
|
||||||
return self.data["Author"]
|
return self.data["authors"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def isbn(self):
|
def isbn(self):
|
||||||
"""pulls out the isbn13 field from the csv line data"""
|
"""pulls out the isbn13 field from the csv line data"""
|
||||||
return unquote_string(self.data["ISBN13"])
|
return unquote_string(self.data["isbn_13"])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def shelf(self):
|
def shelf(self):
|
||||||
"""the goodreads shelf field"""
|
"""the goodreads shelf field"""
|
||||||
if self.data["Exclusive Shelf"]:
|
return self.data.get("shelf")
|
||||||
return GOODREADS_SHELVES.get(self.data["Exclusive Shelf"])
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def review(self):
|
def review(self):
|
||||||
"""a user-written review, to be imported with the book data"""
|
"""a user-written review, to be imported with the book data"""
|
||||||
return self.data["My Review"]
|
return self.data["review_body"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rating(self):
|
def rating(self):
|
||||||
"""x/5 star rating for a book"""
|
"""x/5 star rating for a book"""
|
||||||
if self.data.get("My Rating", None):
|
if self.data.get("rating"):
|
||||||
return int(self.data["My Rating"])
|
return float(self.data["rating"])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def date_added(self):
|
def date_added(self):
|
||||||
"""when the book was added to this dataset"""
|
"""when the book was added to this dataset"""
|
||||||
if self.data["Date Added"]:
|
if self.data.get("date_added"):
|
||||||
return timezone.make_aware(dateutil.parser.parse(self.data["Date Added"]))
|
return timezone.make_aware(dateutil.parser.parse(self.data["date_added"]))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def date_started(self):
|
def date_started(self):
|
||||||
"""when the book was started"""
|
"""when the book was started"""
|
||||||
if "Date Started" in self.data and self.data["Date Started"]:
|
if self.data.get("date_started"):
|
||||||
return timezone.make_aware(dateutil.parser.parse(self.data["Date Started"]))
|
return timezone.make_aware(dateutil.parser.parse(self.data["date_started"]))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def date_read(self):
|
def date_read(self):
|
||||||
"""the date a book was completed"""
|
"""the date a book was completed"""
|
||||||
if self.data["Date Read"]:
|
if self.data.get("date_finished"):
|
||||||
return timezone.make_aware(dateutil.parser.parse(self.data["Date Read"]))
|
return timezone.make_aware(
|
||||||
|
dateutil.parser.parse(self.data["date_finished"])
|
||||||
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -185,8 +177,8 @@ class ImportItem(models.Model):
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
# pylint: disable=consider-using-f-string
|
# pylint: disable=consider-using-f-string
|
||||||
return "<{!r}Item {!r}>".format(self.data["import_source"], self.data["Title"])
|
return "<{!r}Item {!r}>".format(self.data["import_source"], self.data["title"])
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
# pylint: disable=consider-using-f-string
|
# pylint: disable=consider-using-f-string
|
||||||
return "{} by {}".format(self.data["Title"], self.data["Author"])
|
return "{} by {}".format(self.data["title"], self.data["authors"])
|
||||||
|
|
Loading…
Reference in a new issue