def main(wf):
import argparse
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('query', default=None, type=str)
args = parser.parse_args()
log.debug('args : {}'.format(args))
items = wf.cached_data('papers_all', read_papers_entries,
max_age=600) # cache 600 seconds
log.debug('Cached {} items from Papers3'.format(len(items)))
# fuzzy-search by query
# http://www.deanishe.net/alfred-workflow/user-manual/filtering.html?highlight=match_all
ret = wf.filter(args.query, items,
key=lambda t: (t['title'] + ' ' +
t['author names'] + ' ' +
t['bundle name'] + ' ' +
t['keyword names']),
match_on=(workflow.MATCH_ALL ^ workflow.MATCH_ALLCHARS),
min_score=20,
include_score=True)
#ret.sort(key=lambda t: t[1], reverse=True)
if not ret:
wf.add_item('No matchings', icon=workflow.ICON_WARNING)
for entry, score, _ in ret:
title, authors = entry['title'], entry['author names']
bundle, year = entry['bundle name'], entry['publication year']
citekey = entry['citekey']
wf.add_item(title=title,
subtitle=authors + (" (%s %s)" % (bundle, year)), #+ (" (%.3f)" % score),
modifier_subtitles={
'alt' : citekey,
'shift' : 'Copy the BibTeX record of ' + citekey,
},
valid=True,
arg=citekey,
uid=citekey,
type='file',
icon='icon.png'
)
wf.send_feedback()
return 0
评论列表
文章目录