mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
Add v2ex python plugin demo.
This commit is contained in:
BIN
Plugins/Wox.Plugin.V2ex/Images/app.ico
Normal file
BIN
Plugins/Wox.Plugin.V2ex/Images/app.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
34
Plugins/Wox.Plugin.V2ex/main.py
Normal file
34
Plugins/Wox.Plugin.V2ex/main.py
Normal 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")
|
||||
13
Plugins/Wox.Plugin.V2ex/plugin.json
Normal file
13
Plugins/Wox.Plugin.V2ex/plugin.json
Normal file
@@ -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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user