def create_example_phrases(): example_phrases = [] plugins_to_always_invoke = set() regexes = {} # add baseline nonsense parses: example_phrases.append(commanding.Phrase("", ["ihrfeiiehrgogiheog"])) example_phrases.append(commanding.Phrase("", ["ihrfeio iehrgogih eog"])) example_phrases.append(commanding.Phrase("", ["eyfght oehrgueig erobf", ["ehheiog","hegoegn"]])) example_phrases.append(commanding.Phrase("", ["wurt turt gurt", ["~burt", "nurt"]])) example_phrases.append(commanding.Phrase("", [["~uirguieg", "hgeough egoiheroi"]])) example_phrases.append(commanding.Phrase("", [["~uirguieg", "hgeoughegoiheroi"]])) for plugin in os.listdir(plugin_dir): if os.path.isdir(os.path.join(plugin_dir, plugin)): plugin_name, extension = os.path.splitext(plugin) if extension == '.bundle': examples_file = os.path.join(plugin_dir, plugin, "examples.txt") examples_file = i18n.find_localized_path(examples_file) if os.path.exists(examples_file): for line in codecs.open(examples_file, 'r', 'utf-8'): line = line.strip() if line.startswith('!'): if line == '!always_invoke': plugins_to_always_invoke.add(plugin_name) elif line.startswith('!regex '): _, field_name, regex = line.split(' ', 2) regexes[field_name[1:]] = regex elif len(line): example_phrases.append(parse_example_to_phrase(plugin_name, line)) return (example_phrases, plugins_to_always_invoke, regexes)
def results(parsed, original_query): benzine = "yes" query = "~dieselquery" if (parsed.get('~benzinequery', "nobenzin") != "nobenzin"): if parsed["~benzinequery"]: benzine = "benzine" query = "~benzinequery" elif parsed["~dieselquery"]: benzine = "diesel" elif parsed["~dieselquery"]: benzine = "diesel" title = i18n.localstr("Gas Price for '{0}'").format(parsed[query]) return { "title": title, "html": open(i18n.find_localized_path("mehrtanken.html")).read().replace( "SEARCHQUERY", parsed[query]).replace("FUELSETTING", benzine).replace( "light-mode", "dark-mode" if dark_mode() else "light-mode"), "webview_transparent_background": True }
def results(parsed, original_query): icon_file = i18n.find_localized_path("Icon.png") return { "title": i18n.localstr("Open AirDrop"), "run_args": [], "html": html_template.format(icon_file), "webview_transparent_background": True }
def results(parsed, original): import json return { "title": i18n.localstr("External IP Address / Useragent"), "html": open(i18n.find_localized_path("ipuseragent.html")).read().replace("light-mode", "dark-mode" if dark_mode() else "light-mode"), "pass_result_of_output_function_as_first_run_arg": True, "webview_transparent_background": True }
def results(parsed, original): import json return { "title": i18n.localstr("Yes or no?!"), "html": open(i18n.find_localized_path("yesno.html")).read(), "pass_result_of_output_function_as_first_run_arg": True, "webview_transparent_background": True }
def results(fields, original_query): query = fields['~query'] title = i18n.localstr('Search Unicode characters for \'{0}\'').format(query) html = open(i18n.find_localized_path('unicode.html')).read().decode('utf-8').replace("%query%", query) return { "title": title, "html": html, "webview_transparent_background": True }
def results(parsed, original_query): return { "title": i18n.localstr("Excuse"), "run_args": ['http://www.programmerexcuses.com'], "html" : open(i18n.find_localized_path("excuse.html")).read(), "webview_user_agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53", "webview_links_open_in_browser": True, "webview_transparent_background": True }
def results(parsed, original_query): location = parsed['~location'] title = i18n.localstr('"{0}" weather').format(location) html = open(i18n.find_localized_path("weather.html")).read().replace("<!--LOCATION-->", location).replace("<!--UNITS-->", "metric" if use_metric() else "imperial").replace("<!--APPEARANCE-->", "dark" if dark_mode() else "light") return { "title": title, "html": html, "webview_transparent_background": True, "run_args": location }
def results(parsed, original): import json return { "title": i18n.localstr("External IP Address / Useragent"), "html": open(i18n.find_localized_path("ipuseragent.html")).read() .replace("light-mode", "dark-mode" if dark_mode() else "light-mode") .replace("#{local-ip}", socket.gethostbyname(socket.gethostname())), "pass_result_of_output_function_as_first_run_arg": True, "webview_transparent_background": True }
def results(parsed, original_query): return { "title": i18n.localstr("Excuse"), "run_args": ['http://www.programmerexcuses.com'], "html": open(i18n.find_localized_path("excuse.html")).read(), "webview_user_agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53", "webview_links_open_in_browser": True, "webview_transparent_background": True }
def results(parsed, original_query): location = parsed['~location'] title = i18n.localstr('Time in "{0}"').format(location) html = open(i18n.find_localized_path("timezone.html")).read().replace("[PLACEHOLDER]", location) return { "title": title, "html": html, "webview_transparent_background": True, "run_args": location }
def results(parsed, original_query): location = parsed['~location'] title = i18n.localstr("Time in '{0}'").format(location) html = open(i18n.find_localized_path("timezone.html")).read().replace("[PLACEHOLDER]", location).replace("light-mode", "dark-mode" if dark_mode() else "light-mode") return { "title": title, "html": html, "webview_transparent_background": True, "run_args": location }
def results(parsed, original_query): location = parsed['~site'] location = location.split('://')[-1] # strip protocol title = i18n.localstr("Is '{0}' up?").format(location) html = open(i18n.find_localized_path("wrapper.html")).read().replace("[PLACEHOLDER]", location).replace("light-mode", "dark-mode" if dark_mode() else "light-mode") return { "title": title, "html": html, "webview_transparent_background": True, "run_args": location }
def results(parsed, original): import json path = "gifbot.html"; html = open(i18n.find_localized_path(path)).read().replace("var nullValue = null;", "var nullValue = \"{0}\";").replace('{0}', parsed['~query']).replace("light-mode", "dark-mode" if dark_mode() else "light-mode") return { "title": i18n.localstr(u"\"{0}\" GIFs (Press cmd + c to copy link)").format(parsed['~query']), "html": html, "pass_result_of_output_function_as_first_run_arg": True, "run_args": ["abc"], "webview_transparent_background": True, "webview_links_open_in_browser": True }
def results(parsed, original_query): location = parsed['~location'] title = i18n.localstr('Time in "{0}"').format(location) html = open(i18n.find_localized_path("timezone.html")).read().replace( "[PLACEHOLDER]", location).replace("<!--APPEARANCE-->", "dark" if dark_mode() else "light") return { "title": title, "html": html, "webview_transparent_background": True, "run_args": location }
def results(parsed, original_query): location = parsed['~location'] title = i18n.localstr('"{0}" weather').format(location) html = open(i18n.find_localized_path("weather.html")).read().decode( 'utf-8').replace("<!--LOCATION-->", location).replace( "<!--UNITS-->", "metric" if use_metric() else "imperial").replace( "<!--APPEARANCE-->", "dark" if dark_mode() else "light") return { "title": title, "html": html, "webview_transparent_background": True, "run_args": [location] }
def results(parsed, original_query): location = parsed['~site'] location = location.split('://')[-1] # strip protocol title = i18n.localstr("Is '{0}' up?").format(location) html = open(i18n.find_localized_path("wrapper.html")).read().replace( "[PLACEHOLDER]", location).replace("light-mode", "dark-mode" if dark_mode() else "light-mode") return { "title": title, "html": html, "webview_transparent_background": True, "run_args": location }
def results(fields, original_query): html = open(i18n.find_localized_path('unicode.html')).read().decode('utf-8') if("~emoji" in fields): query = fields['~emoji'] html = html.replace("%query%", query).replace("%type%", "emojis") title = i18n.localstr('Search emojis for \'{0}\'').format(query) else: query = fields['~query'] html = html.replace("%query%", query).replace("%type%", "characters") title = i18n.localstr('Search unicode characters for \'{0}\'').format(query) return { "title": title, "html": html, "webview_transparent_background": True, "run_args": [], "pass_result_of_output_function_as_first_run_arg": True }
def results(fields, original_query): html = open( i18n.find_localized_path('unicode.html')).read().decode('utf-8') if ("~emoji" in fields): query = fields['~emoji'] html = html.replace("%query%", query).replace("%type%", "emojis") title = i18n.localstr('Search emojis for \'{0}\'').format(query) else: query = fields['~query'] html = html.replace("%query%", query).replace("%type%", "characters") title = i18n.localstr('Search unicode characters for \'{0}\'').format( query) return { "title": title, "html": html, "webview_transparent_background": True }
def results(parsed, original_query): benzine = "yes" query = "~dieselquery" if(parsed.get('~benzinequery', "nobenzin") != "nobenzin"): if parsed["~benzinequery"]: benzine = "benzine" query = "~benzinequery" elif parsed["~dieselquery"]: benzine = "diesel" elif parsed["~dieselquery"]: benzine = "diesel" title = i18n.localstr("Gas Price for '{0}'").format(parsed[query]) return { "title": title, "html": open(i18n.find_localized_path("mehrtanken.html")).read().replace("SEARCHQUERY", parsed[query]).replace("FUELSETTING",benzine).replace("light-mode", "dark-mode" if dark_mode() else "light-mode"), "webview_transparent_background": True }
def results(parsed, original): import json path = "imagebot.html" html = open(i18n.find_localized_path(path)).read().replace( "var nullValue = null;", "var nullValue = \"{0}\";").replace('{0}', parsed['~query']).replace( "light-mode", "dark-mode" if dark_mode() else "light-mode") return { "title": i18n.localstr( u"\"{0}\" Random Image (Press cmd + c to copy link)").format( parsed['~query']), "html": html, "pass_result_of_output_function_as_first_run_arg": True, "run_args": ["abc"], "webview_transparent_background": True, "webview_links_open_in_browser": True }
def create_example_phrases(): example_phrases = [] plugins_to_always_invoke = set() regexes = {} # add baseline nonsense parses: example_phrases.append(commanding.Phrase("", ["ihrfeiiehrgogiheog"])) example_phrases.append(commanding.Phrase("", ["ihrfeio iehrgogih eog"])) example_phrases.append(commanding.Phrase("", ["eyfght oehrgueig erobf", ["ehheiog","hegoegn"]])) example_phrases.append(commanding.Phrase("", ["wurt turt gurt", ["~burt", "nurt"]])) example_phrases.append(commanding.Phrase("", [["~uirguieg", "hgeough egoiheroi"]])) example_phrases.append(commanding.Phrase("", [["~uirguieg", "hgeough egoiheroi"]])) example_phrases.append(commanding.Phrase("", ["what", ["~uirguieg", "hgeough egoiheroi"]])) example_phrases.append(commanding.Phrase("", [["~uirguieg", "hgeough egoiheroi ehgiegeg"]])) example_phrases.append(commanding.Phrase("", [["~uirguieg", "hgeough egoiheroi ehgiegeg riehg hierohgi"]])) example_phrases.append(commanding.Phrase("", [["~uirguieg", "hgeoughegoiheroi"]])) for plugin in os.listdir(plugin_dir): if os.path.isdir(os.path.join(plugin_dir, plugin)): plugin_name, extension = os.path.splitext(plugin) if extension == '.bundle': examples_file = os.path.join(plugin_dir, plugin, "examples.txt") examples_file = i18n.find_localized_path(examples_file) if os.path.exists(examples_file): for line in codecs.open(examples_file, 'r', 'utf-8'): line = line.strip() if line.startswith('!'): if line == '!always_invoke': plugins_to_always_invoke.add(plugin_name) elif line.startswith('!regex '): _, field_name, regex = line.split(' ', 2) regexes[field_name[1:]] = regex elif len(line): example_phrases.append(parse_example_to_phrase(plugin_name, line)) return (example_phrases, plugins_to_always_invoke, regexes)
example_phrases.append(commanding.Phrase("", ["ihrfeio iehrgogih eog"])) example_phrases.append( commanding.Phrase("", ["eyfght oehrgueig erobf", ["ehheiog", "hegoegn"]])) example_phrases.append( commanding.Phrase("", ["wurt turt gurt", ["~burt", "nurt"]])) example_phrases.append( commanding.Phrase("", [["~uirguieg", "hgeough egoiheroi"]])) example_phrases.append( commanding.Phrase("", [["~uirguieg", "hgeoughegoiheroi"]])) for plugin in os.listdir(plugin_dir): if os.path.isdir(os.path.join(plugin_dir, plugin)): plugin_name, extension = os.path.splitext(plugin) if extension == '.bundle': examples_file = os.path.join(plugin_dir, plugin, "examples.txt") examples_file = i18n.find_localized_path(examples_file) if os.path.exists(examples_file): for line in codecs.open(examples_file, 'r', 'utf-8'): line = line.strip() if line.startswith('!'): if line == '!always_invoke': plugins_to_always_invoke.add(plugin_name) elif line.startswith('!regex '): _, field_name, regex = line.split(' ', 2) regexes[field_name[1:]] = regex elif len(line): example_phrases.append( parse_example_to_phrase(plugin_name, line)) def parse_query(query, supplemental_tags):
regexes = {} # add baseline nonsense parses: example_phrases.append(commanding.Phrase("", ["ihrfeiiehrgogiheog"])) example_phrases.append(commanding.Phrase("", ["ihrfeio iehrgogih eog"])) example_phrases.append(commanding.Phrase("", ["eyfght oehrgueig erobf", ["ehheiog","hegoegn"]])) example_phrases.append(commanding.Phrase("", ["wurt turt gurt", ["~burt", "nurt"]])) example_phrases.append(commanding.Phrase("", [["~uirguieg", "hgeough egoiheroi"]])) example_phrases.append(commanding.Phrase("", [["~uirguieg", "hgeoughegoiheroi"]])) for plugin in os.listdir(plugin_dir): if os.path.isdir(os.path.join(plugin_dir, plugin)): plugin_name, extension = os.path.splitext(plugin) if extension == '.bundle': examples_file = os.path.join(plugin_dir, plugin, "examples.txt") examples_file = i18n.find_localized_path(examples_file) if os.path.exists(examples_file): for line in open(examples_file): line = line.strip() if line.startswith('!'): if line == '!always_invoke': plugins_to_always_invoke.add(plugin_name) elif line.startswith('!regex '): _, field_name, regex = line.split(' ', 2) regexes[field_name[1:]] = regex elif len(line): example_phrases.append(parse_example_to_phrase(plugin_name, line)) def parse_query(query, supplemental_tags): parsed = commanding.parse_phrase(query, example_phrases, regexes, supplemental_tags) if parsed == None or parsed.intent == '':