update to new api, cleanup json

This commit is contained in:
j 2009-07-14 18:34:49 +02:00
parent 99e498b077
commit 2cba80d79c

View file

@ -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):
@ -93,12 +96,19 @@ class MovieId(models.Model):
def json(self):
json = {}
for key in ('imdb_id',
keys = [
'title',
'director',
'year',
'imdb_id',
'amg_id',
'oxdb_id',
'wikipedia_url',
'impawards_url',
'rottentomatoes_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