From 2cba80d79cea35b1cde97f035cb8ec2f8dee6687 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 14 Jul 2009 18:34:49 +0200 Subject: [PATCH] update to new api, cleanup json --- lookup/models.py | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/lookup/models.py b/lookup/models.py index 7d12a92..a6ce658 100644 --- a/lookup/models.py +++ b/lookup/models.py @@ -55,14 +55,12 @@ class MovieId(models.Model): def updateFromWikipedia(self): if self.wikipedia_id: - wikipedia_url = "http://en.wikipedia.org/wiki/%s" % self.wikipedia_id + wikipedia_url = oxweb.wikipedia.getUrl(self.wikipedia_id) data = oxweb.wikipedia.getMovieData(wikipedia_url) _key = {} - for key in ('imdb_id', - 'amg_id', - 'rottentomatoes_id'): + for key in ('imdb_id', 'amg_id'): if key in data: - if data[key]: + if data[key] and not getattr(self, _key.get(key, key)): setattr(self, _key.get(key, key), data[key]) self.save() @@ -76,8 +74,13 @@ class MovieId(models.Model): for key in ('title', 'year', 'series title', 'episode title', 'season', 'episode'): if key in data and data[key]: setattr(self, _key.get(key, key), data[key]) - directors = oxweb.imdb.getMovieCredits(self.imdb_id)['directors'] + directors = [] + credits = oxweb.imdb.getMovieCredits(self.imdb_id) + if 'directors' in credits: + directors = credits['directors'] self.director = ', '.join([stripTags(d[0]) for d in directors]) + if not self.oxdb_id: + self.gen_oxdb_id() self.save() def gen_oxdb_id(self): @@ -92,13 +95,20 @@ class MovieId(models.Model): self.save() def json(self): - json = {} - for key in ('imdb_id', - 'amg_id', - 'oxdb_id', - 'wikipedia_url', - 'impawards_url', - 'rottentomatoes_id'): + json = {} + keys = [ + 'title', + 'director', + 'year', + 'imdb_id', + 'amg_id', + 'oxdb_id', + 'wikipedia_id', + 'impawards_id', + ] + if self.episode > -1: + keys += ['episode', 'season', 'episode_title', 'series_title'] + for key in keys: value = getattr(self, key) if value: json[key] = value