update to new api, cleanup json
This commit is contained in:
parent
99e498b077
commit
2cba80d79c
1 changed files with 23 additions and 13 deletions
|
@ -55,14 +55,12 @@ class MovieId(models.Model):
|
||||||
|
|
||||||
def updateFromWikipedia(self):
|
def updateFromWikipedia(self):
|
||||||
if self.wikipedia_id:
|
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)
|
data = oxweb.wikipedia.getMovieData(wikipedia_url)
|
||||||
_key = {}
|
_key = {}
|
||||||
for key in ('imdb_id',
|
for key in ('imdb_id', 'amg_id'):
|
||||||
'amg_id',
|
|
||||||
'rottentomatoes_id'):
|
|
||||||
if key in data:
|
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])
|
setattr(self, _key.get(key, key), data[key])
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
@ -76,8 +74,13 @@ class MovieId(models.Model):
|
||||||
for key in ('title', 'year', 'series title', 'episode title', 'season', 'episode'):
|
for key in ('title', 'year', 'series title', 'episode title', 'season', 'episode'):
|
||||||
if key in data and data[key]:
|
if key in data and data[key]:
|
||||||
setattr(self, _key.get(key, key), 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])
|
self.director = ', '.join([stripTags(d[0]) for d in directors])
|
||||||
|
if not self.oxdb_id:
|
||||||
|
self.gen_oxdb_id()
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def gen_oxdb_id(self):
|
def gen_oxdb_id(self):
|
||||||
|
@ -93,12 +96,19 @@ class MovieId(models.Model):
|
||||||
|
|
||||||
def json(self):
|
def json(self):
|
||||||
json = {}
|
json = {}
|
||||||
for key in ('imdb_id',
|
keys = [
|
||||||
|
'title',
|
||||||
|
'director',
|
||||||
|
'year',
|
||||||
|
'imdb_id',
|
||||||
'amg_id',
|
'amg_id',
|
||||||
'oxdb_id',
|
'oxdb_id',
|
||||||
'wikipedia_url',
|
'wikipedia_id',
|
||||||
'impawards_url',
|
'impawards_id',
|
||||||
'rottentomatoes_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[key] = value
|
||||||
|
|
Loading…
Reference in a new issue