add v2ex workflow

This commit is contained in:
qianlifeng
2014-01-12 21:02:39 +08:00
parent 2249bbb0f5
commit 820d0cde86
9 changed files with 128 additions and 74 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -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")

View File

@@ -0,0 +1,8 @@
[plugin]
ActionKeyword = v2ex
Name = WinAlfred.V2ex
Author = qianlifeng
Version = 0.1
Language = python
Description = workflow for v2ex
ExecuteFile = main.py

View File

@@ -111,7 +111,11 @@ namespace WinAlfred.WorkflowInstaller
string winalfred = AppDomain.CurrentDomain.BaseDirectory + "WinAlfred.exe"; string winalfred = AppDomain.CurrentDomain.BaseDirectory + "WinAlfred.exe";
if (File.Exists(winalfred)) if (File.Exists(winalfred))
{ {
Process.Start(winalfred, "reloadWorkflows"); ProcessStartInfo info = new ProcessStartInfo(winalfred, "reloadWorkflows")
{
UseShellExecute = true
};
Process.Start(info);
MessageBox.Show("You have installed workflow " + plugin.Name + " successfully."); MessageBox.Show("You have installed workflow " + plugin.Name + " successfully.");
} }
else else

View File

@@ -4,6 +4,7 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
using Microsoft.VisualBasic.ApplicationServices; using Microsoft.VisualBasic.ApplicationServices;
using WinAlfred.Commands;
using StartupEventArgs = System.Windows.StartupEventArgs; using StartupEventArgs = System.Windows.StartupEventArgs;
namespace WinAlfred namespace WinAlfred
@@ -57,12 +58,14 @@ namespace WinAlfred
base.OnStartup(e); base.OnStartup(e);
window = new MainWindow(); window = new MainWindow();
window.ShowApp(e.Args); window.ShowApp();
window.ParseArgs(e.Args);
} }
public void Activate(string[] commandLine) public void Activate(string[] args)
{ {
window.ShowApp(commandLine); window.ShowApp();
window.ParseArgs(args);
} }
} }
} }

View File

@@ -59,9 +59,9 @@ namespace WinAlfred
private void InitialTray() private void InitialTray()
{ {
notifyIcon = new NotifyIcon { Text = "WinAlfred", Icon = Properties.Resources.app, Visible = true }; notifyIcon = new NotifyIcon { Text = "WinAlfred", Icon = Properties.Resources.app, Visible = true };
notifyIcon.Click += (o, e) => ShowWinAlfred(null); notifyIcon.Click += (o, e) => ShowWinAlfred();
System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem("Open"); System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem("Open");
open.Click += (o, e) => ShowWinAlfred(null); open.Click += (o, e) => ShowWinAlfred();
System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("Exit"); System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("Exit");
exit.Click += (o, e) => CloseApp(); exit.Click += (o, e) => CloseApp();
System.Windows.Forms.MenuItem[] childen = { open, exit }; System.Windows.Forms.MenuItem[] childen = { open, exit };
@@ -78,7 +78,7 @@ namespace WinAlfred
{ {
if (!IsVisible) if (!IsVisible)
{ {
ShowWinAlfred(null); ShowWinAlfred();
} }
else else
{ {
@@ -132,7 +132,15 @@ namespace WinAlfred
Hide(); Hide();
} }
private void ShowWinAlfred(string[] args) private void ShowWinAlfred()
{
Show();
Activate();
tbQuery.Focus();
tbQuery.SelectAll();
}
public void ParseArgs(string[] args)
{ {
if (args != null && args.Length > 0) if (args != null && args.Length > 0)
{ {
@@ -147,15 +155,11 @@ namespace WinAlfred
{ {
string query = args[1]; string query = args[1];
tbQuery.Text = query; tbQuery.Text = query;
tbQuery.SelectAll();
} }
break; break;
} }
} }
Show();
Activate();
tbQuery.Focus();
tbQuery.SelectAll();
} }
private void SetAutoStart(bool IsAtuoRun) private void SetAutoStart(bool IsAtuoRun)
@@ -261,9 +265,9 @@ namespace WinAlfred
HideWinAlfred(); HideWinAlfred();
} }
public void ShowApp(string[] args) public void ShowApp()
{ {
ShowWinAlfred(args); ShowWinAlfred();
} }
public void ShowMsg(string title, string subTitle, string iconPath) public void ShowMsg(string title, string subTitle, string iconPath)

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Windows.Forms;
using WinAlfred.Helper; using WinAlfred.Helper;
using WinAlfred.Plugin; using WinAlfred.Plugin;
using WinAlfred.Plugin.System; using WinAlfred.Plugin.System;
@@ -11,7 +12,7 @@ namespace WinAlfred.PluginLoader
{ {
public abstract class BasePluginLoader public abstract class BasePluginLoader
{ {
private static string PluginPath = "Plugins"; private static string PluginPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins";
private static string PluginConfigName = "plugin.ini"; private static string PluginConfigName = "plugin.ini";
protected static List<PluginMetadata> pluginMetadatas = new List<PluginMetadata>(); protected static List<PluginMetadata> pluginMetadatas = new List<PluginMetadata>();
public abstract List<PluginPair> LoadPlugin(); public abstract List<PluginPair> LoadPlugin();
@@ -70,8 +71,8 @@ namespace WinAlfred.PluginLoader
metadata.Version = ini.GetSetting("plugin", "Version"); metadata.Version = ini.GetSetting("plugin", "Version");
metadata.PluginType = PluginType.ThirdParty; metadata.PluginType = PluginType.ThirdParty;
metadata.ActionKeyword = ini.GetSetting("plugin", "ActionKeyword"); metadata.ActionKeyword = ini.GetSetting("plugin", "ActionKeyword");
metadata.ExecuteFilePath = AppDomain.CurrentDomain.BaseDirectory + directory + "\\" + ini.GetSetting("plugin", "ExecuteFile"); metadata.ExecuteFilePath = directory + "\\" + ini.GetSetting("plugin", "ExecuteFile");
metadata.PluginDirecotry = AppDomain.CurrentDomain.BaseDirectory + directory + "\\"; metadata.PluginDirecotry = directory + "\\";
metadata.ExecuteFileName = ini.GetSetting("plugin", "ExecuteFile"); metadata.ExecuteFileName = ini.GetSetting("plugin", "ExecuteFile");
if (!AllowedLanguage.IsAllowed(metadata.Language)) if (!AllowedLanguage.IsAllowed(metadata.Language))

View File

@@ -28,7 +28,7 @@ namespace WinAlfred.PluginLoader
ChangeQuery = s => window.ChangeQuery(s), ChangeQuery = s => window.ChangeQuery(s),
CloseApp = window.CloseApp, CloseApp = window.CloseApp,
HideApp = window.HideApp, HideApp = window.HideApp,
ShowApp = () => window.ShowApp(null), ShowApp = () => window.ShowApp(),
ShowMsg = (title, subTitle, iconPath) => window.ShowMsg(title, subTitle, iconPath) ShowMsg = (title, subTitle, iconPath) => window.ShowMsg(title, subTitle, iconPath)
})); }));
} }

View File

@@ -1,56 +1,56 @@
using System.Reflection; using System.Reflection;
using System.Resources; using System.Resources;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows; using System.Windows;
// 有关程序集的常规信息通过以下 // 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改 // 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。 // 与程序集关联的信息。
[assembly: AssemblyTitle("WinAlfredWPF")] [assembly: AssemblyTitle("WinAlfred")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")] [assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("WinAlfredWPF")] [assembly: AssemblyProduct("WinAlfred")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2013")] [assembly: AssemblyCopyright("Copyright © qianlifeng 2014")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 使此程序集中的类型 // 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。 // 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
//若要开始生成可本地化的应用程序,请在 //若要开始生成可本地化的应用程序,请在
//<PropertyGroup> 中的 .csproj 文件中 //<PropertyGroup> 中的 .csproj 文件中
//设置 <UICulture>CultureYouAreCodingWith</UICulture>。例如,如果您在源文件中 //设置 <UICulture>CultureYouAreCodingWith</UICulture>。例如,如果您在源文件中
//使用的是美国英语,请将 <UICulture> 设置为 en-US。然后取消 //使用的是美国英语,请将 <UICulture> 设置为 en-US。然后取消
//对以下 NeutralResourceLanguage 特性的注释。更新 //对以下 NeutralResourceLanguage 特性的注释。更新
//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。 //以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo( [assembly: ThemeInfo(
ResourceDictionaryLocation.None, //主题特定资源词典所处位置 ResourceDictionaryLocation.None, //主题特定资源词典所处位置
//(在页面或应用程序资源词典中 //(在页面或应用程序资源词典中
// 未找到某个资源的情况下使用) // 未找到某个资源的情况下使用)
ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
//(在页面、应用程序或任何主题特定资源词典中 //(在页面、应用程序或任何主题特定资源词典中
// 未找到某个资源的情况下使用) // 未找到某个资源的情况下使用)
)] )]
// 程序集的版本信息由下面四个值组成: // 程序集的版本信息由下面四个值组成:
// //
// 主版本 // 主版本
// 次版本 // 次版本
// 生成号 // 生成号
// 修订号 // 修订号
// //
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”: // 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: log4net.Config.XmlConfigurator(Watch = true)] [assembly: log4net.Config.XmlConfigurator(Watch = true)]