Skip to content

Commit

Permalink
Merge pull request #10 from codycodes/dev
Browse files Browse the repository at this point in the history
1.0.3
  • Loading branch information
codycodes authored Aug 29, 2020
2 parents 30ec1a1 + 9339277 commit 6eb6e04
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
18 changes: 14 additions & 4 deletions src/alfred_books.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -98,17 +107,18 @@ 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',
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)
Expand Down
21 changes: 16 additions & 5 deletions src/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ 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.genre = genre if genre else ''
self.is_new = "True" if is_new else "False"
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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 6eb6e04

Please sign in to comment.