movie title searches can do without beeing updated every 24 hours

This commit is contained in:
j 2009-08-19 23:00:31 +02:00
parent ddae01323a
commit 7202fcb391
2 changed files with 6 additions and 6 deletions

View file

@ -28,17 +28,17 @@ google.find(query, max_results)
FIXME: how search depper than first page? FIXME: how search depper than first page?
''' '''
DEFAULT_MAX_RESULTS = 10 DEFAULT_MAX_RESULTS = 10
DEFAULT_TIMEOUT = 24*60*60
def getUrl(url, data=None, headers=oxlib.net.DEFAULT_HEADERS): def getUrl(url, data=None, headers=oxlib.net.DEFAULT_HEADERS, timeout=DEFAULT_TIMEOUT):
google_timeout=24*60*60 return oxlib.cache.getUrl(url, data, headers, timeout)
return oxlib.cache.getUrl(url, data, headers, google_timeout)
def quote_plus(s): def quote_plus(s):
return urllib.quote_plus(s.encode('utf-8')) 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) 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>' + \ link_re = r'<a href="(?P<url>[^"]*?)" class=l.*?>(?P<name>.*?)</a>' + \
r'.*?(?:<br>|<table.*?>)' + \ r'.*?(?:<br>|<table.*?>)' + \
r'(?P<desc>.*?)' + '(?:<font color=#008000>|<a)' r'(?P<desc>.*?)' + '(?:<font color=#008000>|<a)'

View file

@ -44,7 +44,7 @@ def getMovieId(title, director='', year=''):
query = 'site:imdb.com %s "%s"' % (director, title) query = 'site:imdb.com %s "%s"' % (director, title)
else: else:
query = 'site:imdb.com "%s"' % title 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'): if url.startswith('http://www.imdb.com/title/tt'):
return url[28:35] return url[28:35]
return '' return ''