From 5e253ba9ac5049b63ee21d9af1a46a3529b54b6c Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 8 Jul 2012 10:20:28 +0200 Subject: [PATCH] group output by services --- oxdata/lookup/models.py | 63 ++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/oxdata/lookup/models.py b/oxdata/lookup/models.py index a5d1dcb..b68f298 100644 --- a/oxdata/lookup/models.py +++ b/oxdata/lookup/models.py @@ -14,6 +14,7 @@ from ox import stripTags import ox.web.archive import ox.web.imdb import ox.web.wikipedia +import ox.web.allmovie def getMovieIdByImdbId(imdb_id): @@ -143,30 +144,58 @@ class MovieId(models.Model): def json(self): json = {} - keys = [ + json['imdb.com'] = {} + for key in [ 'title', 'director', 'year', 'imdb_id', - 'oxdb_id', - 'amg_id', - 'wikipedia_id', - 'criterion_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 - if 'director' in json: - json['directors'] = json.pop('director').split(', ') - if 'year' in json and json['year']: - json['year'] = int(json['year']) + json['imdb.com'][{'imdb_id': 'id'}.get(key, key)] = value + json['imdb.com']['url'] = ox.web.imdb.getUrl(self.imdb_id) - json['suggested_name'] = self.suggested_name() - json['suggested_path'] = self.suggested_path() + if self.amg_id: + json['allmovie.com'] = { + 'id': self.amg_id, + 'url': ox.web.allmovie.getUrl(self.amg_id) + } + if self.wikipedia_id: + json['wikipedia.org'] = { + 'id': self.wikipedia_id, + 'url': ox.web.wikipedia.getUrl(self.wikipedia_id) + } + if self.criterion_id: + json['criterion.com'] = { + 'id': self.criterion_id, + 'url': ox.web.criterion.getUrl(self.criterion_id) + } + if self.impawards_id: + json['impawards.com'] = { + 'id': self.impawards_id, + 'url': ox.web.impawards.getUrl(self.impawards_id) + } + if self.archiveorg_id: + json['archive.org'] = { + 'id': self.archiveorg_id, + 'url': ox.web.archive.getUrl(self.archive_id) + } + + if self.episode > -1: + keys = ['episode', 'season', 'episode_title', 'series_title'] + for key in keys: + value = getattr(self, key) + if value: + json['imdb.com'][key] = value + if 'director' in json['imdb.com']: + json['imdb.com']['directors'] = json['imdb.com'].pop('director').split(', ') + if 'year' in json['imdb.com'] and json['imdb.com']['year']: + json['imdb.com']['year'] = int(json['imdb.com']['year']) + + json['0xdb.org'] = {} + json['0xdb.org']['suggested_name'] = self.suggested_name() + json['0xdb.org']['suggested_path'] = self.suggested_path() return json