ox.web under_score api rewrite
This commit is contained in:
parent
bb35daa95c
commit
a4fd3c930f
29 changed files with 268 additions and 285 deletions
|
|
@ -7,25 +7,24 @@ from lxml.html import document_fromstring
|
|||
from ox.cache import read_url
|
||||
from ox import find_re, strip_tags
|
||||
|
||||
def getUrl(id):
|
||||
def get_url(id=None, imdb=None):
|
||||
if imdb:
|
||||
url = "http://www.imdb.com/title/tt%s/criticreviews" % imdb
|
||||
data = read_url(url)
|
||||
metacritic_url = find_re(data, '"(http://www.metacritic.com/movie/.*?)"')
|
||||
return metacritic_url or None
|
||||
return 'http://www.metacritic.com/movie/%s' % id
|
||||
|
||||
def getId(url):
|
||||
def get_id(url):
|
||||
return url.split('/')[-1]
|
||||
|
||||
def getUrlByImdb(imdb):
|
||||
url = "http://www.imdb.com/title/tt%s/criticreviews" % imdb
|
||||
data = read_url(url)
|
||||
metacritic_url = find_re(data, '"(http://www.metacritic.com/movie/.*?)"')
|
||||
return metacritic_url or None
|
||||
|
||||
def getMetacriticShowUrl(title):
|
||||
def get_show_url(title):
|
||||
title = quote(title)
|
||||
url = "http://www.metacritic.com/search/process?ty=6&ts=%s&tfs=tvshow_title&x=0&y=0&sb=0&release_date_s=&release_date_e=&metascore_s=&metascore_e=" % title
|
||||
data = read_url(url)
|
||||
return find_re(data, '(http://www.metacritic.com/tv/shows/.*?)\?')
|
||||
|
||||
def getData(url):
|
||||
def get_data(url):
|
||||
data = read_url(url, unicode=True)
|
||||
doc = document_fromstring(data)
|
||||
score = filter(lambda s: s.attrib.get('property') == 'v:average',
|
||||
|
|
@ -57,7 +56,7 @@ def getData(url):
|
|||
|
||||
return {
|
||||
'critics': metacritics,
|
||||
'id': getId(url),
|
||||
'id': get_id(url),
|
||||
'score': score,
|
||||
'url': url,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue