From 72789c983944cd61b56278106d3386ce03881c35 Mon Sep 17 00:00:00 2001 From: codycodes Date: Sat, 6 Jul 2019 14:23:03 -0700 Subject: [PATCH 1/3] :sparkles: add filter for new books or not --- src/alfred_books.py | 12 +++++++++++- src/book.py | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/alfred_books.py b/src/alfred_books.py index 5b8777e..a1aa5be 100644 --- a/src/alfred_books.py +++ b/src/alfred_books.py @@ -25,7 +25,7 @@ def main(wf): if args and wf.args[0]: switch = wf.args[0].split()[0] # log.debug('SWITCH: ' + switch) - switches = [u'-a', u'-t', u'-g', u'-h'] + switches = [u'-a', u'-t', u'-g', u'-h', u'-n'] if any([switch in switches]): switch = switch[:2] log.debug('SWITCH: ' + switch) @@ -85,9 +85,18 @@ def main(wf): largetext='-t search via title,\n' + '-a search via author,\n' + '-g search via genre,\n' + + '-n "True/False" filters to show new books or not,\n' '-h show switches (this one),\n' + 'no option(s) search by title and author' ) + elif option == '-n': + log.debug('-n input') + books = wf.filter( + query, + books, + key=lambda book: u' '.join(book.is_new), + match_on=MATCH_ALL ^ MATCH_ALLCHARS, min_score=30 + ) else: books = wf.filter( query, @@ -109,6 +118,7 @@ def main(wf): icontype='fileicon', quicklookurl=b.path, largetext=b.title + u', by ' + b.author + + u'\nIs new: ' + b.is_new + u'\nGenre: ' + b.genre + u'\nCompleted: ' + b.read_pct + u'\nDescription:\n' + b.book_desc) diff --git a/src/book.py b/src/book.py index 87ab19a..94302ea 100644 --- a/src/book.py +++ b/src/book.py @@ -16,7 +16,7 @@ def __init__(self, title, path, author, book_desc, is_new, genre, self.author = author self.book_desc = book_desc if book_desc \ else "No book description for this title available in Books" - self.is_new = is_new + self.is_new = "True" if is_new else "False" self.genre = genre if genre else '' self.read_pct = '0%' if not read_pct else str(read_pct * 100)[:4] + '%' Book.books += 1 From 2c6a30eb4f66f53cba0ac63251ba2db6315f4eee Mon Sep 17 00:00:00 2001 From: codes Date: Sat, 29 Aug 2020 11:02:53 -0700 Subject: [PATCH 2/3] :bug: Get columns by name not index --- src/book.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/book.py b/src/book.py index 94302ea..25ebda3 100644 --- a/src/book.py +++ b/src/book.py @@ -17,7 +17,7 @@ def __init__(self, title, path, author, book_desc, is_new, genre, self.book_desc = book_desc if book_desc \ else "No book description for this title available in Books" self.is_new = "True" if is_new else "False" - self.genre = genre if genre else '' + self.genre = genre if genre else 'No genre for this title available in Books' self.read_pct = '0%' if not read_pct else str(read_pct * 100)[:4] + '%' Book.books += 1 @@ -45,14 +45,25 @@ def get_book_db(): def get_books(): conn = sqlite3.connect(get_book_db()) + conn.row_factory = sqlite3.Row c = conn.cursor() c.execute('''SELECT "_rowid_",* FROM "main"."ZBKLIBRARYASSET" ORDER BY "_rowid_" ASC LIMIT 0, 49999;''') data = c.fetchall() books = [] - for b in data: + for row in data: + row = dict(row) # check if path exists - if (b[72]): - books.append(Book(b[78], b[72], b[56], b[57], b[18], b[66], b[50])) + if row['ZPATH'] is not None: + book = Book( + title=row['ZTITLE'], + path=row['ZPATH'] if os.path.exists(row['ZPATH']) else None, + author=row['ZAUTHOR'], + book_desc=row['ZBOOKDESCRIPTION'], + is_new=row['ZISNEW'], + genre=row['ZGENRE'], + read_pct=row['ZREADINGPROGRESS'], + ) + books.append(book) conn.close() return books From 93392777ec0569b028f43f4eb1b2ae306b8716cd Mon Sep 17 00:00:00 2001 From: codes Date: Sat, 29 Aug 2020 11:03:37 -0700 Subject: [PATCH 3/3] :bug: Inform user if book not downloaded --- src/alfred_books.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/alfred_books.py b/src/alfred_books.py index a1aa5be..ebc8ce1 100644 --- a/src/alfred_books.py +++ b/src/alfred_books.py @@ -107,12 +107,12 @@ def main(wf): ) for b in books: - if b.genre == '': - b.genre = 'No genre for this title available in Books' wf.add_item(type='file', title=b.title, valid=True, - subtitle=b.author, + subtitle=b.author if b.path is not None else + 'Please download file in books app first' + ' to open in Alfred Books', arg=b.path, icon=b.path, icontype='fileicon',