fix trivia links

This commit is contained in:
j 2016-09-05 18:32:50 +02:00
parent 9a53675b20
commit 98795d3a25
2 changed files with 19 additions and 17 deletions

View file

@ -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 fix_links(t):
def quote_string(string): def quote_string(string):
return quote(string).replace('_', '%09').replace('%20', '_') return quote(string).replace('_', '%09').replace('%20', '_')
def fix_names(m): def fix_names(m):
return '<a href="/name=%s">%s</a>' % ( return '<a href="/name=%s">%s</a>' % (
quote_string(m.group(2).encode('utf-8')), m.group(2) 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): def fix_titles(m):
return '<a href="/title=%s">%s</a>' % ( return '<a href="/title=%s">%s</a>' % (
quote_string(m.group(2).encode('utf-8')), m.group(2) quote_string(m.group(2).encode('utf-8')), m.group(2)
) )
t = re.sub('<a href="(/title/.*?/)">(.*?)</a>', fix_titles, t)
def fix_links(t):
t = re.sub('<a href="(/name/.*?)">(.*?)</a>', fix_names, t)
t = re.sub('<a href="(/title/.*?)">(.*?)</a>', fix_titles, t)
return t return t
if 'trivia' in data: if 'trivia' in data: