2013-12-23 15:53:38 +00:00
|
|
|
#encoding=utf8
|
|
|
|
import requests
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
import json
|
2014-01-11 07:02:17 +00:00
|
|
|
import webbrowser
|
2013-12-20 17:20:17 +00:00
|
|
|
|
2014-01-10 16:19:14 +00:00
|
|
|
def query(key):
|
|
|
|
k = key.split(" ")[1]
|
|
|
|
if not k:
|
|
|
|
return ""
|
|
|
|
r = requests.get('http://movie.douban.com/subject_search?search_text=' + k)
|
|
|
|
bs = BeautifulSoup(r.text)
|
|
|
|
results = []
|
|
|
|
for i in bs.select(".article table .pl2"):
|
|
|
|
res = {}
|
|
|
|
title = i.select("a")[0].text.replace("\n","").replace(" ","")
|
|
|
|
score = i.select("span.rating_nums")[0].text if i.select("span.rating_nums") else "0"
|
2014-01-11 07:02:17 +00:00
|
|
|
res["Title"] = title.split("/")[0]
|
|
|
|
year = i.select("p.pl")[0].text.split("-")[0] if i.select("p.pl")[0] else "Null"
|
|
|
|
alias = title.split("/")[1] if len(title.split("/")) >= 2 else "Null"
|
|
|
|
res["SubTitle"] = "Year: " + year + " Score: " + score + " Alias: " + alias
|
2014-01-10 16:19:14 +00:00
|
|
|
res["ActionName"] = "openUrl"
|
2014-01-11 07:02:17 +00:00
|
|
|
res["IcoPath"] = "Images\\movies.png"
|
2014-01-10 16:19:14 +00:00
|
|
|
res["ActionPara"] = i.select("a[href]")[0]["href"]
|
|
|
|
results.append(res)
|
|
|
|
return json.dumps(results)
|
|
|
|
|
2014-02-09 12:55:18 +00:00
|
|
|
def openUrl(context,url):
|
|
|
|
#shift + enter
|
|
|
|
#if context["SpecialKeyState"]["ShiftPressed"] == "True":
|
2014-01-11 07:02:17 +00:00
|
|
|
webbrowser.open(url)
|
2013-12-20 17:20:17 +00:00
|
|
|
|
2013-12-23 15:53:38 +00:00
|
|
|
if __name__ == "__main__":
|
2014-01-10 16:19:14 +00:00
|
|
|
print query("movie geo")
|