Skip to content

Commit

Permalink
Merge pull request #12 from codycodes/dev
Browse files Browse the repository at this point in the history
v1.0.4
  • Loading branch information
codycodes authored Sep 12, 2020
2 parents 6eb6e04 + 815bc9b commit 53202bc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
33 changes: 15 additions & 18 deletions src/alfred_books.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: utf-8
import sys
import book
from workflow import Workflow, ICON_WARNING, ICON_INFO, MATCH_ALL, \
Expand All @@ -24,20 +25,17 @@ def main(wf):
option = None
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', u'-n']
if any([switch in switches]):
switch = switch[:2]
log.debug('SWITCH: ' + switch)
query, option = wf.args[0].split(switch)[1], switch
else:
query, option = wf.args[0], None
query = wf.decode(query)
else:
query = None
# max age of 20 seconds to reduce querying database
# and make it blazingly fast
books = wf.cached_data('books', book.get_books, max_age=20)
# books = book.get_books()

# Don't do anything else if there are no books
if not books:
Expand All @@ -46,8 +44,6 @@ def main(wf):
wf.send_feedback()
return 0

log.debug('QUERY: ' + str(query) + ', OPTION: ' + str(option))

# show help with no space required
if query or option == '-h':
if option:
Expand All @@ -56,23 +52,23 @@ def main(wf):
books = wf.filter(
query,
books,
key=lambda book: u' '.join(book.author),
key=lambda book: ' '.join(book.author),
match_on=MATCH_ALL ^ MATCH_ALLCHARS, min_score=30
)
elif option == '-t':
log.debug('-t input')
books = wf.filter(
query,
books,
key=lambda book: u' '.join(book.title),
key=lambda book: ' '.join(book.title),
match_on=MATCH_ALL ^ MATCH_ALLCHARS, min_score=30
)
elif option == '-g':
log.debug('-g input')
books = wf.filter(
query,
books,
key=lambda book: u' '.join(book.genre),
key=lambda book: ' '.join(book.genre),
match_on=MATCH_ALL ^ MATCH_ALLCHARS, min_score=30
)
elif option == '-h':
Expand All @@ -94,15 +90,15 @@ def main(wf):
books = wf.filter(
query,
books,
key=lambda book: u' '.join(book.is_new),
key=lambda book: ' '.join(book.is_new),
match_on=MATCH_ALL ^ MATCH_ALLCHARS, min_score=30
)
else:
books = wf.filter(
query,
books,
key=lambda book: u' '.join(book.title) + u' ' +
u' '.join(book.author),
key=lambda book: ' '.join(book.title) + ' ' +
' '.join(book.author),
match_on=MATCH_ALL ^ MATCH_ALLCHARS, min_score=30
)

Expand All @@ -117,16 +113,17 @@ def main(wf):
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)
largetext=b.title + ', by ' + b.author +
'\nIs new: ' + b.is_new +
'\nGenre: ' + b.genre +
'\nCompleted: ' + b.read_pct +
'\nDescription:\n' + b.book_desc)
wf.send_feedback()


if __name__ == u"__main__":
wf = Workflow(help_url='https://github.com/codycodes/alfred-books/issues',
update_settings={'github_slug': 'codycodes/alfred-books'})
update_settings={'github_slug': 'codycodes/alfred-books'},
normalization='NFD')
log = wf.logger
sys.exit(wf.run(main))
9 changes: 5 additions & 4 deletions src/book.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import sqlite3
import os

BOOKS_PATH = '/Library/Containers/com.apple.iBooksX/Data/Documents/BKLibrary/'
BOOKS_PATH = os.path.expanduser('~'
'/Library/Containers/'
'com.apple.iBooksX/Data/Documents/BKLibrary/')


class Book:
Expand Down Expand Up @@ -35,11 +37,10 @@ def display_count(self):


def get_book_db():
book_dir = os.path.expanduser('~' + BOOKS_PATH)
dbs = []
dbs += [each for each in os.listdir(book_dir)
dbs += [each for each in os.listdir(BOOKS_PATH)
if (each.endswith('.sqlite') and each.startswith('BKLibrary'))]
db_path = book_dir + dbs[0]
db_path = BOOKS_PATH + dbs[0]
return db_path


Expand Down

0 comments on commit 53202bc

Please sign in to comment.