Skip to content

Commit

Permalink
Ensure UTF-8
Browse files Browse the repository at this point in the history
  • Loading branch information
codycodes committed Sep 12, 2020
1 parent 9339277 commit cd08170
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 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 Down Expand Up @@ -32,6 +33,7 @@ def main(wf):
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
Expand All @@ -46,7 +48,7 @@ def main(wf):
wf.send_feedback()
return 0

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

# show help with no space required
if query or option == '-h':
Expand All @@ -56,23 +58,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 +96,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 +119,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))

0 comments on commit cd08170

Please sign in to comment.