From 8936617bd4d5fa6c7cff4f0d4409a8398b3702fc Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 5 Aug 2011 17:50:18 +0200 Subject: [PATCH] reviews actor --- pandora/item/models.py | 30 +++++++++++++++++++++++++++--- pandora/settings.py | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index 77548ec..f8e41cb 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -4,6 +4,7 @@ from __future__ import division, with_statement from datetime import datetime import os.path +import re import subprocess from glob import glob import shutil @@ -187,11 +188,14 @@ class Item(models.Model): def reviews(self): reviews = self.get('reviews', []) - _reviews = {} + _reviews = [] for r in reviews: for url in settings.REVIEW_WHITELIST: if url in r[0]: - _reviews[settings.REVIEW_WHITELIST[url]] = r[0] + _reviews.append({ + 'source': settings.REVIEW_WHITELIST[url], + 'url': r[0] + }) return _reviews def update_external(self): @@ -217,6 +221,23 @@ class Item(models.Model): else: data['actor'] = [c[0] for c in data['cast']] data['actor'] = data['actor'] + data['cast'] = map(lambda x: {'actor': x[0], 'character': x[1]}, data['cast']) + if 'trivia' in data: + def fix_links(t): + def fix_names(m): + return '%s' % ( + quote(m.group(2).encode('utf-8')), m.group(2) + ) + t = re.sub('(.*?)', fix_names, t) + def fix_titles(m): + return '%s' % ( + quote(m.group(2).encode('utf-8')), m.group(2) + ) + t = re.sub('(.*?)', fix_titles, t) + return t + data['trivia'] = [fix_links(t) for t in data['trivia']] + + #filter reviews self.external_data = data self.save() @@ -416,6 +437,9 @@ class Item(models.Model): if value: i[key] = value + if 'reviews' in i: + i['reviews'] = self.reviews() + if not keys or 'poster' in keys: i['poster'] = self.get_poster() if keys and 'posters' in keys: @@ -467,7 +491,7 @@ class Item(models.Model): if isinstance(values[0], basestring): values = [values[0], ] else: - values = [i[1] for i in values] + values = [i['character'] for i in values] else: values = self.get(key, '') if isinstance(values, list): diff --git a/pandora/settings.py b/pandora/settings.py index ae1823c..a9bb57e 100644 --- a/pandora/settings.py +++ b/pandora/settings.py @@ -202,7 +202,7 @@ TRANSMISSON_PASSWORD = 'transmission' #Movie related settings REVIEW_WHITELIST = { - u'filmcritic.com': u'Filmcritic', + u'.filmcritic.com': u'Filmcritic', u'metacritic.com': u'Metacritic', u'nytimes.com': u'New York Times', u'rottentomatoes.com': u'Rotten Tomatoes',