diff --git a/Plugins/Wox.Plugin.V2ex/Images/app.ico b/Plugins/Wox.Plugin.V2ex/Images/app.ico new file mode 100644 index 000000000..b0c3435fc Binary files /dev/null and b/Plugins/Wox.Plugin.V2ex/Images/app.ico differ diff --git a/Plugins/Wox.Plugin.V2ex/main.py b/Plugins/Wox.Plugin.V2ex/main.py new file mode 100644 index 000000000..ef3a1a504 --- /dev/null +++ b/Plugins/Wox.Plugin.V2ex/main.py @@ -0,0 +1,34 @@ +#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/Plugins/Wox.Plugin.V2ex/plugin.json b/Plugins/Wox.Plugin.V2ex/plugin.json new file mode 100644 index 000000000..91cace1f5 --- /dev/null +++ b/Plugins/Wox.Plugin.V2ex/plugin.json @@ -0,0 +1,13 @@ +{ + "ID":"D2D2C23B084D411DB66FE0C79D6C2A6H", + "ActionKeyword":"v2ex", + "Name":"Wox.Plugin.v2ex", + "Description":"v2ex viewer", + "Author":"qianlifeng", + "Version":"1.0", + "Language":"python", + "Website":"http://www.getwox.com", + "IcoPath":"Images\\app.ico", + "ExecuteFileName":"main.py" +} + diff --git a/PythonHome/python27.dll b/PythonHome/python27.dll new file mode 100644 index 000000000..5d55cc581 Binary files /dev/null and b/PythonHome/python27.dll differ diff --git a/Wox/RPC/JsonPRCModel.cs b/Wox/JsonRPC/JsonPRCModel.cs similarity index 94% rename from Wox/RPC/JsonPRCModel.cs rename to Wox/JsonRPC/JsonPRCModel.cs index cfcd35930..d123d3757 100644 --- a/Wox/RPC/JsonPRCModel.cs +++ b/Wox/JsonRPC/JsonPRCModel.cs @@ -1,9 +1,7 @@ using System.Collections.Generic; -using System.Windows.Documents; -using Newtonsoft.Json; using Wox.Plugin; -namespace Wox.RPC +namespace Wox.JsonRPC { public class JsonRPCErrorModel { diff --git a/Wox/PluginLoader/BasePlugin.cs b/Wox/PluginLoader/BasePlugin.cs index 3467a03d6..5149d71ca 100644 --- a/Wox/PluginLoader/BasePlugin.cs +++ b/Wox/PluginLoader/BasePlugin.cs @@ -5,8 +5,8 @@ using System.IO; using System.Linq; using System.Text; using Newtonsoft.Json; +using Wox.JsonRPC; using Wox.Plugin; -using Wox.RPC; namespace Wox.PluginLoader { @@ -14,7 +14,7 @@ namespace Wox.PluginLoader { protected PluginInitContext context; - public abstract List GetAllowedLanguages(); + public abstract string SupportedLanguage { get; } protected abstract string ExecuteQuery(Query query); protected abstract string ExecuteAction(JsonRPCRequestModel rpcRequest); diff --git a/Wox/PluginLoader/BasePluginLoader.cs b/Wox/PluginLoader/BasePluginLoader.cs index 6e28efe2c..6bcbd7363 100644 --- a/Wox/PluginLoader/BasePluginLoader.cs +++ b/Wox/PluginLoader/BasePluginLoader.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Wox.Plugin; -using Wox.RPC; namespace Wox.PluginLoader { @@ -11,22 +10,14 @@ namespace Wox.PluginLoader { public virtual List LoadPlugin(List pluginMetadatas) { - List plugins = new List(); - T pluginWrapper = new T(); - List allowedLanguages = pluginWrapper.GetAllowedLanguages(); - List metadatas = pluginMetadatas.Where(o => allowedLanguages.Contains(o.Language.ToUpper())).ToList(); - foreach (PluginMetadata metadata in metadatas) - { - PluginPair pair = new PluginPair() - { - Plugin = pluginWrapper, - Metadata = metadata - }; - plugins.Add(pair); - } + List metadatas = pluginMetadatas.Where(o => pluginWrapper.SupportedLanguage.ToUpper() == o.Language.ToUpper()).ToList(); - return plugins; + return metadatas.Select(metadata => new PluginPair() + { + Plugin = pluginWrapper, + Metadata = metadata + }).ToList(); } } } diff --git a/Wox/PluginLoader/PythonPlugin.cs b/Wox/PluginLoader/PythonPlugin.cs index 423b7e9d7..81ab5c034 100644 --- a/Wox/PluginLoader/PythonPlugin.cs +++ b/Wox/PluginLoader/PythonPlugin.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.IO; +using Wox.JsonRPC; using Wox.Plugin; -using Wox.RPC; namespace Wox.PluginLoader { @@ -9,27 +9,24 @@ namespace Wox.PluginLoader { private static string woxDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath); - public override List GetAllowedLanguages() + public override string SupportedLanguage { - return new List() - { - AllowedLanguage.Python - }; + get { return AllowedLanguage.Python; } } protected override string ExecuteQuery(Query query) { string fileName = Path.Combine(woxDirectory, "PythonHome\\pythonw.exe"); string parameters = string.Format("{0} \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath, - JsonRPC.Send("query", query.GetAllRemainingParameter())); + string.Format(@"{{\""method\"": \""query\"", \""parameters\"": \""{0}\""}}",query.GetAllRemainingParameter())); + return Execute(fileName, parameters); } protected override string ExecuteAction(JsonRPCRequestModel rpcRequest) { string fileName = Path.Combine(woxDirectory, "PythonHome\\pythonw.exe"); - string parameters = string.Format("{0} \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath, - rpcRequest.ToString()); + string parameters = string.Format("{0} \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath,rpcRequest); return Execute(fileName, parameters); } } diff --git a/Wox/RPC/2obywmlm.f50 b/Wox/RPC/2obywmlm.f50 deleted file mode 100644 index 41bfcdc21..000000000 --- a/Wox/RPC/2obywmlm.f50 +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace Wox.RPC -{ - public class JsonRPC - { - public static string Send(string method, List paras) - { - var list = paras.Select(s => string.Format(@"\""{0}\""", s)); - return string.Format(@"{{\""jsonrpc\"": \""2.0\"",\""method\"": \""{0}\"", \""params\"": [{1}], \""id\"": 1}}", - method, string.Join(",", list.ToArray())); - } - - public static string Send(string method, string para) - { - return string.Format(@"{{\""jsonrpc\"": \""2.0\"",\""method\"": \""{0}\"", \""params\"": {1}, \""id\"": 1}}", - method, string.Join(",", list.ToArray())); - } - } -} diff --git a/Wox/RPC/JsonRPC.cs b/Wox/RPC/JsonRPC.cs deleted file mode 100644 index 27c3f7d83..000000000 --- a/Wox/RPC/JsonRPC.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace Wox.RPC -{ - public class JsonRPC - { - public static string Send(string method, List paras) - { - var list = paras.Select(s => string.Format(@"\""{0}\""", s)); - return string.Format(@"{{\""jsonrpc\"": \""2.0\"",\""method\"": \""{0}\"", \""parameters\"": [{1}], \""id\"": 1}}", - method, string.Join(",", list.ToArray())); - } - - public static string Send(string method, string para) - { - return string.Format(@"{{\""jsonrpc\"": \""2.0\"",\""method\"": \""{0}\"", \""parameters\"": \""{1}\"", \""id\"": 1}}", - method, para); - } - } -} diff --git a/Wox/RPC/tr3fzfc4.och b/Wox/RPC/tr3fzfc4.och deleted file mode 100644 index 71a944742..000000000 --- a/Wox/RPC/tr3fzfc4.och +++ /dev/null @@ -1,56 +0,0 @@ -using System.Collections.Generic; -using System.Windows.Documents; -using Newtonsoft.Json; -using Wox.Plugin; - -namespace Wox.RPC -{ - public class JsonRPCErrorModel - { - public int Code { get; set; } - - public string Message { get; set; } - - public string Data { get; set; } - } - - public class JsonRPCModelBase - { - public int Id { get; set; } - - public string JsonRPC { get; set; } - } - - public class JsonRPCResponseModel : JsonRPCModelBase - { - public string Result { get; set; } - - public JsonRPCErrorModel Error { get; set; } - } - - public class JsonRPCQueryResponseModel : JsonRPCResponseModel - { - public new List Result { get; set; } - } - - public class JsonRPCRequestModel : JsonRPCModelBase - { - public string Method { get; set; } - - /// - /// counld be list or string type - /// - public object Parameters { get; set; } - - public override string ToString() - { - if(typeof(Parameters)) - return string.Format(@"{""method"":}",Method,Parameters); - } - } - - public class JsonRPCResult : Result - { - public JsonRPCRequestModel JsonRPCAction { get; set; } - } -} diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index f7775274d..3764b2f4c 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -139,7 +139,6 @@ - Msg.xaml @@ -147,7 +146,7 @@ - +