-
Notifications
You must be signed in to change notification settings - Fork 1
/
find_app_ids.py
67 lines (50 loc) · 2.05 KB
/
find_app_ids.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python
# encoding: utf-8
import sys
import argparse
from workflow import (Workflow, ICON_WEB, ICON_INFO, ICON_WARNING,
PasswordNotFound)
from workflow.background import run_in_background, is_running
import siminfo
def search_key_for_app(app):
"""Generate a string search key for a app"""
elements = []
elements.append(app['name'])
elements.append(app['id'])
elements.append(app['device']['name'])
return u' '.join(elements)
def main(wf):
# build argument parser to parse script args and collect their
# values
parser = argparse.ArgumentParser()
parser.add_argument('query', nargs='?', default=None)
parser.add_argument('--no-watch', dest='include_watch', action='store_false', help='excludes embedded watch apps from results')
# parse the script's arguments
args = parser.parse_args(wf.args)
####################################################################
# View/filter Simulator apps
####################################################################
query = args.query
apps = siminfo.getSimAppResults(wf.cachedir, args.include_watch)
# If script was passed a query, use it to filter posts if we have some
if query and apps:
apps = wf.filter(query, apps, key=search_key_for_app, min_score=20)
if not apps: # we have no data to show, so show a warning and stop
wf.add_item('No apps found', icon=ICON_WARNING)
wf.send_feedback()
return 0
# Loop through the returned posts and add a item for each to
# the list of results for Alfred
for app in apps:
appName = '%s (%s - %s)' % (app['name'], app['device']['name'], app['device']['runtime'])
wf.add_item(title=appName,
subtitle=app['id'],
arg=app['device']['id'] + ' ' + app['id'],
valid=True,
icon=app['icon'])
# Send the results to Alfred as XML
wf.send_feedback()
return 0
if __name__ == u"__main__":
wf = Workflow()
sys.exit(wf.run(main))