2014-07-10 18:39:04 +08:00
|
|
|
#encoding=utf8
|
|
|
|
|
|
|
|
import requests
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
import webbrowser
|
2014-07-10 23:57:08 +08:00
|
|
|
from wox import Wox,WoxAPI
|
2014-07-10 18:39:04 +08:00
|
|
|
|
|
|
|
class HackerNews(Wox):
|
|
|
|
|
|
|
|
def query(self,key):
|
2014-07-18 20:00:55 +08:00
|
|
|
proxies = {}
|
|
|
|
if self.proxy and self.proxy.get("enabled") and self.proxy.get("server"):
|
|
|
|
proxies = {
|
|
|
|
"http": "http://{}:{}".format(self.proxy.get("server"),self.proxy.get("port")),
|
|
|
|
"http": "https://{}:{}".format(self.proxy.get("server"),self.proxy.get("port"))
|
|
|
|
}
|
|
|
|
#self.debug(proxies)
|
|
|
|
r = requests.get('https://news.ycombinator.com/',proxies = proxies)
|
2014-07-10 18:39:04 +08:00
|
|
|
bs = BeautifulSoup(r.text)
|
|
|
|
results = []
|
|
|
|
for i in bs.select(".comhead"):
|
|
|
|
title = i.previous_sibling.text
|
|
|
|
url = i.previous_sibling["href"]
|
2014-07-10 23:57:08 +08:00
|
|
|
results.append({"Title": title ,"IcoPath":"Images/app.ico","JsonRPCAction":{"method": "openUrl","parameters":[url],"dontHideAfterAction":True}})
|
2014-07-10 18:39:04 +08:00
|
|
|
|
|
|
|
return results
|
|
|
|
|
|
|
|
def openUrl(self,url):
|
|
|
|
webbrowser.open(url)
|
2014-07-10 23:57:08 +08:00
|
|
|
#todo:doesn't work when move this line up
|
|
|
|
WoxAPI.change_query(url)
|
2014-07-10 18:39:04 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
HackerNews()
|