Save progress information from imports.

This commit is contained in:
Adam Kelly 2020-04-15 12:13:38 +01:00
parent 60f0aa207d
commit 53ff28b5dc
3 changed files with 27 additions and 2 deletions

View file

@ -2,9 +2,10 @@
import re
import csv
import itertools
import dateutil.parser
from fedireads import books_manager
from fedireads.models import Edition
from fedireads.models import Edition, ReadThrough
# Mapping goodreads -> fedireads shelf titles.
@ -99,6 +100,25 @@ class GoodreadsItem:
def rating(self):
return int(self.line['My Rating'])
@property
def date_added(self):
if self.line['Date Added']:
return dateutil.parser.parse(self.line['Date Added'])
@property
def date_read(self):
if self.line['Date Read']:
return dateutil.parser.parse(self.line['Date Read'])
@property
def reads(self):
return [ReadThrough(
# Date added isn't the start date, but it's (perhaps) better than nothing.
start_date=self.date_added,
finish_date=self.date_read,
pages_read=None,
)]
def __repr__(self):
return "<GoodreadsItem {!r}>".format(self.line['Title'])

View file

@ -2,6 +2,6 @@
from .book import Connector, Book, Work, Edition, Author
from .shelf import Shelf, ShelfBook
from .status import Status, Review, Comment, Quotation
from .status import Favorite, Boost, Tag, Notification
from .status import Favorite, Boost, Tag, Notification, ReadThrough
from .user import User, UserFollows, UserFollowRequest, UserBlocks
from .user import FederatedServer

View file

@ -177,6 +177,11 @@ def handle_import_books(user, items):
recipients = get_recipients(user, 'public')
broadcast(user, activity, recipients)
for read in item.reads:
read.book = item.book
read.user = user
read.save()
if new_books:
message = 'imported {} books'.format(len(new_books))
status = create_status(user, message, mention_books=new_books)