use wikipedia search stupid
This commit is contained in:
parent
9616b3477e
commit
ee442c4090
1 changed files with 10 additions and 25 deletions
|
@ -10,29 +10,14 @@ from imdb import IMDb
|
||||||
from google import google
|
from google import google
|
||||||
|
|
||||||
|
|
||||||
def searchByImdb(imdb_id, title=None, director=None):
|
def searchByImdb(imdb_id):
|
||||||
if not title:
|
if len(imdb_id) != 7: return ''
|
||||||
i = IMDb(imdb_id)
|
url = "http://en.wikipedia.org/w/index.php?title=Special%3ASearch&search=imdb_id%20" + imdb_id + "&fulltext=Search"
|
||||||
title = i.parseTitle()
|
|
||||||
director = i.parseCredits()['director']
|
|
||||||
if director:
|
|
||||||
director = director[0]
|
|
||||||
else:
|
|
||||||
director = ''
|
|
||||||
q = u'%s %s site:en.wikipedia.org' % (title, director)
|
|
||||||
#print q.encode('utf-8')
|
|
||||||
for g in google(q, 7):
|
|
||||||
url = g[1]
|
|
||||||
data = read_url(url)
|
data = read_url(url)
|
||||||
soup = BeautifulSoup(data)
|
soup = BeautifulSoup(data)
|
||||||
edit_url = soup('a', dict(href=re.compile('action=edit'),
|
result = soup('li', {"style":"padding-bottom: 1em;"})
|
||||||
title=re.compile('You can edit this page.')))
|
if result:
|
||||||
if edit_url:
|
url = result[0]('a')[0]['href']
|
||||||
edit_url = edit_url[0]['href']
|
url = "http://en.wikipedia.org%s" % url
|
||||||
edit_url = "http://en.wikipedia.org%s" % edit_url.replace('&', '&')
|
|
||||||
data = read_url(edit_url)
|
|
||||||
w_imdb_id = data.find('imdb_id')
|
|
||||||
if w_imdb_id > 0:
|
|
||||||
if imdb_id in data[w_imdb_id:w_imdb_id+50]:
|
|
||||||
return url
|
return url
|
||||||
return ''
|
return ''
|
||||||
|
|
Loading…
Reference in a new issue