forked from mirrors/bookwyrm
Save progress information from imports.
This commit is contained in:
parent
60f0aa207d
commit
53ff28b5dc
3 changed files with 27 additions and 2 deletions
|
@ -2,9 +2,10 @@
|
||||||
import re
|
import re
|
||||||
import csv
|
import csv
|
||||||
import itertools
|
import itertools
|
||||||
|
import dateutil.parser
|
||||||
|
|
||||||
from fedireads import books_manager
|
from fedireads import books_manager
|
||||||
from fedireads.models import Edition
|
from fedireads.models import Edition, ReadThrough
|
||||||
|
|
||||||
|
|
||||||
# Mapping goodreads -> fedireads shelf titles.
|
# Mapping goodreads -> fedireads shelf titles.
|
||||||
|
@ -99,6 +100,25 @@ class GoodreadsItem:
|
||||||
def rating(self):
|
def rating(self):
|
||||||
return int(self.line['My Rating'])
|
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):
|
def __repr__(self):
|
||||||
return "<GoodreadsItem {!r}>".format(self.line['Title'])
|
return "<GoodreadsItem {!r}>".format(self.line['Title'])
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
from .book import Connector, Book, Work, Edition, Author
|
from .book import Connector, Book, Work, Edition, Author
|
||||||
from .shelf import Shelf, ShelfBook
|
from .shelf import Shelf, ShelfBook
|
||||||
from .status import Status, Review, Comment, Quotation
|
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 User, UserFollows, UserFollowRequest, UserBlocks
|
||||||
from .user import FederatedServer
|
from .user import FederatedServer
|
||||||
|
|
|
@ -177,6 +177,11 @@ def handle_import_books(user, items):
|
||||||
recipients = get_recipients(user, 'public')
|
recipients = get_recipients(user, 'public')
|
||||||
broadcast(user, activity, recipients)
|
broadcast(user, activity, recipients)
|
||||||
|
|
||||||
|
for read in item.reads:
|
||||||
|
read.book = item.book
|
||||||
|
read.user = user
|
||||||
|
read.save()
|
||||||
|
|
||||||
if new_books:
|
if new_books:
|
||||||
message = 'imported {} books'.format(len(new_books))
|
message = 'imported {} books'.format(len(new_books))
|
||||||
status = create_status(user, message, mention_books=new_books)
|
status = create_status(user, message, mention_books=new_books)
|
||||||
|
|
Loading…
Reference in a new issue