Shelve the books.

This commit is contained in:
Adam Kelly
2020-03-25 12:58:27 +00:00
parent ce446d57fc
commit 323c7f8dbf
2 changed files with 19 additions and 1 deletions

View File

@ -5,6 +5,13 @@ from requests import HTTPError
from fedireads import books_manager
# Mapping goodreads -> fedireads shelf titles.
GOODREADS_SHELVES = {
'read': 'read',
'currently-reading': 'reading',
'to-read': 'to-read',
}
def unquote_string(text):
match = re.match(r'="([^"]*)"', text)
if match:
@ -25,7 +32,7 @@ class GoodreadsCsv(object):
self.reader = csv.DictReader(csv_file)
def __iter__(self):
for line in itertools.islice(self.reader, 20, 30):
for line in itertools.islice(self.reader, 30):
entry = GoodreadsItem(line)
try:
entry.resolve()
@ -55,5 +62,10 @@ class GoodreadsItem(object):
if search_results:
return books_manager.get_or_create_book(search_results[0].key)
@property
def shelf(self):
if self.line['Exclusive Shelf']:
return GOODREADS_SHELVES[self.line['Exclusive Shelf']]
def __repr__(self):
return "<GoodreadsItem {!r}>".format(self.line['Title'])