movie title searches can do without beeing updated every 24 hours
This commit is contained in:
parent
ddae01323a
commit
7202fcb391
2 changed files with 6 additions and 6 deletions
|
@ -28,17 +28,17 @@ google.find(query, max_results)
|
|||
FIXME: how search depper than first page?
|
||||
'''
|
||||
DEFAULT_MAX_RESULTS = 10
|
||||
DEFAULT_TIMEOUT = 24*60*60
|
||||
|
||||
def getUrl(url, data=None, headers=oxlib.net.DEFAULT_HEADERS):
|
||||
google_timeout=24*60*60
|
||||
return oxlib.cache.getUrl(url, data, headers, google_timeout)
|
||||
def getUrl(url, data=None, headers=oxlib.net.DEFAULT_HEADERS, timeout=DEFAULT_TIMEOUT):
|
||||
return oxlib.cache.getUrl(url, data, headers, timeout)
|
||||
|
||||
def quote_plus(s):
|
||||
return urllib.quote_plus(s.encode('utf-8'))
|
||||
|
||||
def find(query, max_results=DEFAULT_MAX_RESULTS):
|
||||
def find(query, max_results=DEFAULT_MAX_RESULTS, timeout=DEFAULT_TIMEOUT):
|
||||
url = "http://www.google.com/search?q=%s" % quote_plus(query)
|
||||
data = getUrl(url)
|
||||
data = getUrl(url, timeout=timeout)
|
||||
link_re = r'<a href="(?P<url>[^"]*?)" class=l.*?>(?P<name>.*?)</a>' + \
|
||||
r'.*?(?:<br>|<table.*?>)' + \
|
||||
r'(?P<desc>.*?)' + '(?:<font color=#008000>|<a)'
|
||||
|
|
|
@ -44,7 +44,7 @@ def getMovieId(title, director='', year=''):
|
|||
query = 'site:imdb.com %s "%s"' % (director, title)
|
||||
else:
|
||||
query = 'site:imdb.com "%s"' % title
|
||||
for (name, url, desc) in google.find(query, 3):
|
||||
for (name, url, desc) in google.find(query, 3, timeout=-1):
|
||||
if url.startswith('http://www.imdb.com/title/tt'):
|
||||
return url[28:35]
|
||||
return ''
|
||||
|
|
Loading…
Reference in a new issue