def main(wf):
"""Main function to handle query and request info from Jisho.org.
Args:
wf: An instance of Workflow.
"""
# Get query from Alfred.
query = wf.args[0] if len(wf.args) else None
# Add query result if there is an update.
if wf.update_available:
wf.add_item('A newer version of Jisho Alfred Workflow is available',
'Action this item to download and install the new version',
autocomplete='workflow:update',
icon=ICON_INFO)
try:
# Only fetch results from Jisho.org if it is a valid query.
results = get_results(query) if is_valid_query(query) else []
if results:
# Add results to Alfred, up to the maximum number of results.
for i in range(min(len(results), MAX_NUM_RESULTS)):
add_alfred_result(wf, results[i])
else:
# Add an error result if there was an issue getting results.
error_msg = "Could not find anything matching '%s'" % (query)
wf.add_item(error_msg, arg=query, valid=True, icon=ICON_NOTE)
except:
# Add an error result if there was an issue getting results.
error_msg = "There was an issue retrieving Jisho results"
wf.add_item(error_msg, arg=query, valid=True, icon=ICON_ERROR)
# Send the results to Alfred as XML.
wf.send_feedback()
jisho-alfred-workflow.py 文件源码
python
阅读 22
收藏 0
点赞 0
评论 0
评论列表
文章目录