Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add zhihu search plugin #565

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added PluginDirectories/1/zhihu-search.bundle/Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions PluginDirectories/1/zhihu-search.bundle/examples.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zh ~zhihuquery(a)
12 changes: 12 additions & 0 deletions PluginDirectories/1/zhihu-search.bundle/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"categories" : [
"Utilities"
],
"displayName" : "Zhihu Search",
"name" : "zhihu-search",
"description" : "This is an zhihu search plugin",
"examples" : [
"zh 如何评价",
"zh good morning"
]
}
34 changes: 34 additions & 0 deletions PluginDirectories/1/zhihu-search.bundle/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import urllib
import json
import i18n


def results(parsed, original_query):

search_specs = [
["Zhihu", "~zhihuquery", "https://www.zhihu.com/search?type=content&q="]
]
for name, key, url in search_specs:
if key in parsed:
localizedurl = i18n.localstr(url)
search_url = localizedurl + urllib.quote_plus(parsed[key].encode('UTF-8'))
title = i18n.localstr(
"Search {0} for '{1}'").format(name, parsed[key].encode('UTF-8'))
return {
"title": title,
"run_args": [search_url],
"html": """
<script>
setTimeout(function() {
window.location = %s
}, 500);
</script>
""" % (json.dumps(search_url)),
"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
}


def run(url):
import os
os.system('open "{0}"'.format(url))