update rottentomatoes and metacritic
This commit is contained in:
parent
a4271fd81a
commit
e74dc77ab1
2 changed files with 65 additions and 34 deletions
|
|
@ -6,7 +6,7 @@ from ox.cache import getHeaders, readUrl, readUrlUnicode
|
|||
from ox import findRe, stripTags
|
||||
|
||||
|
||||
def readUrlByImdb(imdb):
|
||||
def getUrlByImdb(imdb):
|
||||
#this would also wor but does not cache:
|
||||
'''
|
||||
from urllib2 import urlopen
|
||||
|
|
@ -21,14 +21,33 @@ def readUrlByImdb(imdb):
|
|||
return "http://www.rottentomatoes.com" + movies[0]
|
||||
return None
|
||||
|
||||
def get_og(data, key):
|
||||
return findRe(data, '<meta property="og:%s".*?content="(.*?)"' % key)
|
||||
|
||||
def getData(url):
|
||||
data = readUrlUnicode(url)
|
||||
data = readUrl(url)
|
||||
r = {}
|
||||
r['title'] = findRe(data, '<h1 class="movie_title">(.*?)</h1>')
|
||||
if '(' in r['title']:
|
||||
r['year'] = findRe(r['title'], '\((\d*?)\)')
|
||||
r['title'] = re.sub('\((\d*?)\)', '', r['title']).strip()
|
||||
r['synopsis'] = findRe(data, '<span id="movie_synopsis_all".*?>(.*?)</span>')
|
||||
r['average rating'] = findRe(data, '<div id="bubble_allCritics".*?>(.*?)</div>').strip()
|
||||
r['title'] = stripTags(re.sub('\((\d*?)\)', '', r['title'])).strip()
|
||||
r['summary'] = stripTags(findRe(data, '<p id="movieSynopsis" class="movie_synopsis" itemprop="description">(.*?)</p>')).strip()
|
||||
r['summary'] = r['summary'].replace('\t', ' ').replace('\n', ' ').replace(' ', ' ').replace(' ', ' ')
|
||||
if not r['summary']:
|
||||
r['summary'] = get_og(data, 'description')
|
||||
|
||||
meter = re.compile('<span id="all-critics-meter" class="meter(.*?)">(.*?)</span>').findall(data)
|
||||
meter = filter(lambda m: m[1].isdigit(), meter)
|
||||
if meter:
|
||||
r['tomatometer'] = meter[0][1]
|
||||
r['rating'] = findRe(data, 'Average Rating: <span>([\d.]+)/10</span>')
|
||||
r['user_score'] = findRe(data, '<span class="meter popcorn numeric ">(\d+)</span>')
|
||||
r['user_rating'] = findRe(data, 'Average Rating: ([\d.]+)/5')
|
||||
poster = get_og(data, 'image')
|
||||
if poster and not 'poster_default.gif' in poster:
|
||||
r['posters'] = [poster]
|
||||
for key in r.keys():
|
||||
if not r[key]:
|
||||
del r[key]
|
||||
return r
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue