Skip to content

Commit

Permalink
Merge pull request #7 from EbookFoundation/bookshelves
Browse files Browse the repository at this point in the history
use selected books
  • Loading branch information
vlee1776 authored Apr 21, 2020
2 parents 979073a + b30a073 commit 9664b72
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions gutenbergtozim/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,11 +753,11 @@ def authors_from_ids(idlist):
# Ex: [None, u'Adventure', u"Children's Literature", u'Christianity',
# u'Detective Fiction', u'Gothic Fiction', u'Harvard Classics', u'Historical Fiction',
# u'Mathematics', u'Plays', u'School Stories', u'Science Fiction']
def bookshelf_list():
return [bookshelf.bookshelf for bookshelf in Book.select().order_by(Book.bookshelf.asc()).group_by(Book.bookshelf)]
def bookshelf_list(books):
return [bookshelf.bookshelf for bookshelf in books.select().order_by(Book.bookshelf.asc()).group_by(Book.bookshelf)]

def bookshelf_list_language(lang):
return [bookshelf.bookshelf for bookshelf in Book.select().where(Book.language == lang).order_by(Book.bookshelf.asc()).group_by(Book.bookshelf)]
def bookshelf_list_language(books,lang):
return [bookshelf.bookshelf for bookshelf in books.select().where(Book.language == lang).order_by(Book.bookshelf.asc()).group_by(Book.bookshelf)]

def export_to_json_helpers(books, static_folder, languages,
formats, project_id, title_search, add_bookshelves):
Expand Down Expand Up @@ -815,7 +815,7 @@ def dumpjs(col, fn, var='json_data'):


if add_bookshelves:
bookshelves = bookshelf_list()
bookshelves = bookshelf_list(books)
for bookshelf in bookshelves:
#exclude the books with no bookshelf data
if bookshelf is None:
Expand All @@ -826,15 +826,15 @@ def dumpjs(col, fn, var='json_data'):
logger.info('\t\tDumping bookshelf_{}_by_popularity.js'.format(bookshelf))
dumpjs(
[book.to_array()
for book in Book.select().where(Book.bookshelf == bookshelf)
for book in books.select().where(Book.bookshelf == bookshelf)
.order_by(Book.downloads.desc())],
'bookshelf_{}_by_popularity.js'.format(bookshelf))

# by title
logger.info('\t\tDumping bookshelf_{}_by_title.js'.format(bookshelf))
dumpjs(
[book.to_array()
for book in Book.select().where(Book.bookshelf== bookshelf)
for book in books.select().where(Book.bookshelf== bookshelf)
.order_by(Book.title.asc())],
'bookshelf_{}_by_title.js'.format(bookshelf))
# by language
Expand All @@ -843,14 +843,14 @@ def dumpjs(col, fn, var='json_data'):
.format(bookshelf, lang))
dumpjs(
[book.to_array()
for book in Book.select().where(Book.language == lang)
for book in books.select().where(Book.language == lang)
.where(Book.bookshelf == bookshelf)
.order_by(Book.downloads.desc())],
'bookshelf_{}_lang_{}_by_popularity.js'.format(bookshelf, lang))

dumpjs(
[book.to_array()
for book in Book.select().where(Book.language == lang)
for book in books.select().where(Book.language == lang)
.where(Book.bookshelf == bookshelf)
.order_by(Book.title.asc())],
'bookshelf_{}_lang_{}_by_title.js'.format(bookshelf, lang))
Expand All @@ -859,7 +859,7 @@ def dumpjs(col, fn, var='json_data'):
for lang_name, lang, lang_count in avail_langs:
logger.info("\t\tDumping bookshelves_lang_{}.js"
.format(lang))
temp = bookshelf_list_language(lang)
temp = bookshelf_list_language(books,lang)
dumpjs(
temp,
'bookshelves_lang_{}.js'.format(lang))
Expand Down

0 comments on commit 9664b72

Please sign in to comment.