forked from Wox-launcher/Wox.Plugin.DoubanMovie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
34 lines (31 loc) · 1.19 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#encoding=utf8
import requests
from bs4 import BeautifulSoup
import json
import webbrowser
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"
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
res["ActionName"] = "openUrl"
res["IcoPath"] = "Images\\movies.png"
res["ActionPara"] = i.select("a[href]")[0]["href"]
results.append(res)
return json.dumps(results)
def openUrl(context,url):
#shift + enter
#if context["SpecialKeyState"]["ShiftPressed"] == "True":
webbrowser.open(url)
if __name__ == "__main__":
print query("movie geo")