group output by services

This commit is contained in:
j 2012-07-08 10:20:28 +02:00
parent ece58dad63
commit 5e253ba9ac

View file

@ -14,6 +14,7 @@ from ox import stripTags
import ox.web.archive import ox.web.archive
import ox.web.imdb import ox.web.imdb
import ox.web.wikipedia import ox.web.wikipedia
import ox.web.allmovie
def getMovieIdByImdbId(imdb_id): def getMovieIdByImdbId(imdb_id):
@ -143,30 +144,58 @@ class MovieId(models.Model):
def json(self): def json(self):
json = {} json = {}
keys = [ json['imdb.com'] = {}
for key in [
'title', 'title',
'director', 'director',
'year', 'year',
'imdb_id', '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) value = getattr(self, key)
if value: if value:
json[key] = value json['imdb.com'][{'imdb_id': 'id'}.get(key, key)] = value
if 'director' in json: json['imdb.com']['url'] = ox.web.imdb.getUrl(self.imdb_id)
json['directors'] = json.pop('director').split(', ')
if 'year' in json and json['year']:
json['year'] = int(json['year'])
json['suggested_name'] = self.suggested_name() if self.amg_id:
json['suggested_path'] = self.suggested_path() 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 return json