fix trivia links
This commit is contained in:
parent
9a53675b20
commit
98795d3a25
2 changed files with 19 additions and 17 deletions
|
@ -131,21 +131,23 @@ class Imdb(models.Model):
|
||||||
def data(self, request=None, timeout=ox.cache.cache_timeout):
|
def data(self, request=None, timeout=ox.cache.cache_timeout):
|
||||||
data = ox.web.imdb.Imdb(self.imdb, timeout=timeout)
|
data = ox.web.imdb.Imdb(self.imdb, timeout=timeout)
|
||||||
data = self.apply_patch(data)
|
data = self.apply_patch(data)
|
||||||
|
|
||||||
|
def quote_string(string):
|
||||||
|
return quote(string).replace('_', '%09').replace('%20', '_')
|
||||||
|
|
||||||
|
def fix_names(m):
|
||||||
|
return '<a href="/name=%s">%s</a>' % (
|
||||||
|
quote_string(m.group(2).encode('utf-8')), m.group(2)
|
||||||
|
)
|
||||||
|
|
||||||
|
def fix_titles(m):
|
||||||
|
return '<a href="/title=%s">%s</a>' % (
|
||||||
|
quote_string(m.group(2).encode('utf-8')), m.group(2)
|
||||||
|
)
|
||||||
|
|
||||||
def fix_links(t):
|
def fix_links(t):
|
||||||
def quote_string(string):
|
t = re.sub('<a href="(/name/.*?)">(.*?)</a>', fix_names, t)
|
||||||
return quote(string).replace('_', '%09').replace('%20', '_')
|
t = re.sub('<a href="(/title/.*?)">(.*?)</a>', fix_titles, t)
|
||||||
def fix_names(m):
|
|
||||||
return '<a href="/name=%s">%s</a>' % (
|
|
||||||
quote_string(m.group(2).encode('utf-8')), m.group(2)
|
|
||||||
)
|
|
||||||
t = re.sub('<a href="(/name/.*?/)">(.*?)</a>', fix_names, t)
|
|
||||||
|
|
||||||
def fix_titles(m):
|
|
||||||
return '<a href="/title=%s">%s</a>' % (
|
|
||||||
quote_string(m.group(2).encode('utf-8')), m.group(2)
|
|
||||||
)
|
|
||||||
t = re.sub('<a href="(/title/.*?/)">(.*?)</a>', fix_titles, t)
|
|
||||||
|
|
||||||
return t
|
return t
|
||||||
|
|
||||||
if 'trivia' in data:
|
if 'trivia' in data:
|
||||||
|
@ -194,7 +196,7 @@ class Imdb(models.Model):
|
||||||
if key in c:
|
if key in c:
|
||||||
c[key] = ox.sanitize_html(fix_links(c[key]))
|
c[key] = ox.sanitize_html(fix_links(c[key]))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def info(self, key):
|
def info(self, key):
|
||||||
movie_id = get_movie_id(imdb_id=self.imdb)
|
movie_id = get_movie_id(imdb_id=self.imdb)
|
||||||
return movie_id and movie_id.info(key) or 0
|
return movie_id and movie_id.info(key) or 0
|
||||||
|
|
|
@ -15,7 +15,7 @@ def getId(request, data):
|
||||||
if movie:
|
if movie:
|
||||||
response['data'] = movie.json()
|
response['data'] = movie.json()
|
||||||
else:
|
else:
|
||||||
response['status'] = {'text':'not found', 'code': 404}
|
response['status'] = {'text': 'not found', 'code': 404}
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(getId)
|
actions.register(getId)
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ def getData(request, data):
|
||||||
data = i.data(request)
|
data = i.data(request)
|
||||||
response['data'] = data
|
response['data'] = data
|
||||||
else:
|
else:
|
||||||
response['status'] = {'text':'not found', 'code': 404}
|
response['status'] = {'text': 'not found', 'code': 404}
|
||||||
|
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(getData)
|
actions.register(getData)
|
||||||
|
|
Loading…
Reference in a new issue