diff --git a/Plugins/Wox.Plugin.HackerNews/Images/app.ico b/Plugins/Wox.Plugin.HackerNews/Images/app.ico new file mode 100644 index 0000000000..a415c1eaf1 Binary files /dev/null and b/Plugins/Wox.Plugin.HackerNews/Images/app.ico differ diff --git a/Plugins/Wox.Plugin.HackerNews/main.py b/Plugins/Wox.Plugin.HackerNews/main.py new file mode 100644 index 0000000000..faf4be9231 --- /dev/null +++ b/Plugins/Wox.Plugin.HackerNews/main.py @@ -0,0 +1,27 @@ +#encoding=utf8 + +from __future__ import unicode_literals +import requests +from bs4 import BeautifulSoup +import json +import webbrowser +from wox import Wox + +class HackerNews(Wox): + + def query(self,key): + r = requests.get('https://news.ycombinator.com/') + bs = BeautifulSoup(r.text) + results = [] + for i in bs.select(".comhead"): + title = i.previous_sibling.text + url = i.previous_sibling["href"] + results.append({"Title": title ,"IcoPath":"Images/app.ico","JsonRPCAction":{"method": "openUrl", "parameters": url}}) + + return results + + def openUrl(self,url): + webbrowser.open(url) + +if __name__ == "__main__": + HackerNews() diff --git a/Plugins/Wox.Plugin.V2ex/plugin.json b/Plugins/Wox.Plugin.HackerNews/plugin.json similarity index 53% rename from Plugins/Wox.Plugin.V2ex/plugin.json rename to Plugins/Wox.Plugin.HackerNews/plugin.json index 91cace1f5f..d3c608d32b 100644 --- a/Plugins/Wox.Plugin.V2ex/plugin.json +++ b/Plugins/Wox.Plugin.HackerNews/plugin.json @@ -1,8 +1,8 @@ { - "ID":"D2D2C23B084D411DB66FE0C79D6C2A6H", - "ActionKeyword":"v2ex", - "Name":"Wox.Plugin.v2ex", - "Description":"v2ex viewer", + "ID":"D2D2C23B084D411DB66FE0C79D6C1B7H", + "ActionKeyword":"hn", + "Name":"Hacker News", + "Description":"Hacker News@https://news.ycombinator.com", "Author":"qianlifeng", "Version":"1.0", "Language":"python", @@ -10,4 +10,3 @@ "IcoPath":"Images\\app.ico", "ExecuteFileName":"main.py" } - diff --git a/Plugins/Wox.Plugin.HackerNews/run.bat b/Plugins/Wox.Plugin.HackerNews/run.bat new file mode 100644 index 0000000000..8f795eb291 --- /dev/null +++ b/Plugins/Wox.Plugin.HackerNews/run.bat @@ -0,0 +1 @@ +d:\Personal\wox.jsonrpc\Output\Debug\PythonHome\python.exe main.py "{\"jsonrpc\": \"2.0\", \"method\": \"query\", \"params\": \"l\", \"id\": 1} diff --git a/Plugins/Wox.Plugin.V2ex/Images/app.ico b/Plugins/Wox.Plugin.V2ex/Images/app.ico deleted file mode 100644 index b0c3435fc3..0000000000 Binary files a/Plugins/Wox.Plugin.V2ex/Images/app.ico and /dev/null differ diff --git a/Plugins/Wox.Plugin.V2ex/main.py b/Plugins/Wox.Plugin.V2ex/main.py deleted file mode 100644 index ef3a1a504d..0000000000 --- a/Plugins/Wox.Plugin.V2ex/main.py +++ /dev/null @@ -1,34 +0,0 @@ -#encoding=utf8 - -from __future__ import unicode_literals -import requests -from bs4 import BeautifulSoup -import json -import webbrowser - -def safeSelectText(s,path): - return s.select(path)[0].text if len(s.select(path)) > 0 else "" - -def query(key): - r = requests.get('http://v2ex.com/?tab=all') - bs = BeautifulSoup(r.text) - results = [] - for i in bs.select(".box div.item"): - res = {} - title = safeSelectText(i,".item_title") - subTitle = safeSelectText(i,".fade") - url = "http://v2ex.com" + i.select(".item_title a")[0]["href"] - - res["Title"] = title - res["SubTitle"] = subTitle - res["ActionName"] = "openUrl" - res["IcoPath"] = "Images\\app.ico" - res["ActionPara"] = url - results.append(res) - return json.dumps(results) - -def openUrl(url): - webbrowser.open(url) - -if __name__ == "__main__": - print query("movie geo") diff --git a/PythonHome/Lib/wox.py b/PythonHome/Lib/wox.py new file mode 100644 index 0000000000..7f3be97e4f --- /dev/null +++ b/PythonHome/Lib/wox.py @@ -0,0 +1,25 @@ +#encoding=utf8 +import json +import sys +import inspect + +class Wox(object): + """ + Wox python plugin base + """ + + def __init__(self): + rpc_request = json.loads(sys.argv[1]) + request_method_name = rpc_request.get("method") + request_parameters = rpc_request.get("parameters") + methods = inspect.getmembers(self, predicate=inspect.ismethod) + + request_method = dict(methods)[request_method_name] + results = request_method(request_parameters) + print json.dumps({"result": results}) + + def query(self,query): + """ + sub class need to override this method + """ + return [] diff --git a/Wox.Plugin/HttpProxy.cs b/Wox.Plugin/HttpProxy.cs new file mode 100644 index 0000000000..967844374e --- /dev/null +++ b/Wox.Plugin/HttpProxy.cs @@ -0,0 +1,10 @@ +namespace Wox.Plugin +{ + public class HttpProxy + { + public string Address { get; set; } + public int Port { get; set; } + public string UserName { get; set; } + public string Password { get; set; } + } +} \ No newline at end of file diff --git a/Wox.Plugin/PluginInitContext.cs b/Wox.Plugin/PluginInitContext.cs index f38b1c1c70..edc343538b 100644 --- a/Wox.Plugin/PluginInitContext.cs +++ b/Wox.Plugin/PluginInitContext.cs @@ -14,6 +14,8 @@ namespace Wox.Plugin /// public IPublicAPI API { get; set; } + public HttpProxy Proxy { get; set; } + #region Legacy APIs [Obsolete("This method has been obsoleted, use API.ShellRun instead")] diff --git a/Wox.Plugin/PluginPair.cs b/Wox.Plugin/PluginPair.cs index 7ec5796d64..9d09f7d105 100644 --- a/Wox.Plugin/PluginPair.cs +++ b/Wox.Plugin/PluginPair.cs @@ -9,6 +9,5 @@ namespace Wox.Plugin { public IPlugin Plugin { get; set; } public PluginMetadata Metadata { get; set; } - public PluginInitContext InitContext { get; set; } } } diff --git a/Wox.Plugin/Wox.Plugin.csproj b/Wox.Plugin/Wox.Plugin.csproj index 558dc86573..a0dcbb2fca 100644 --- a/Wox.Plugin/Wox.Plugin.csproj +++ b/Wox.Plugin/Wox.Plugin.csproj @@ -45,6 +45,7 @@ + diff --git a/Wox/PluginLoader/Plugins.cs b/Wox/PluginLoader/Plugins.cs index 2fa0542c1b..beec41e792 100644 --- a/Wox/PluginLoader/Plugins.cs +++ b/Wox/PluginLoader/Plugins.cs @@ -20,21 +20,14 @@ namespace Wox.PluginLoader plugins.AddRange(new BasePluginLoader().LoadPlugin(pluginMetadatas)); Forker forker = new Forker(); - foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin)) + foreach (PluginPair pluginPair in plugins) { - IPlugin plugin1 = plugin; - PluginPair pluginPair = plugins.FirstOrDefault(o => o.Plugin == plugin1); - if (pluginPair != null) + PluginPair pair = pluginPair; + forker.Fork(() => pair.Plugin.Init(new PluginInitContext() { - PluginMetadata metadata = pluginPair.Metadata; - pluginPair.InitContext = new PluginInitContext() - { - CurrentPluginMetadata = metadata, - API = App.Window - }; - - forker.Fork(() => plugin1.Init(pluginPair.InitContext)); - } + CurrentPluginMetadata = pair.Metadata, + API = App.Window + })); } forker.Join();