[imdb] fillobj adaptation

This commit is contained in:
Julien Veyssier 2013-03-07 01:22:11 +01:00
commit cf1029a3f9
5 changed files with 41 additions and 45 deletions

View file

@ -78,9 +78,9 @@ class ImdbBackend(BaseBackend, ICapCinema):
def fill_movie(self, movie, fields): def fill_movie(self, movie, fields):
if 'other_titles' in fields or 'release_date' in fields\ if 'other_titles' in fields or 'release_date' in fields\
or 'duration' in fields or 'description' in fields\ or 'duration' in fields or 'country' in fields\
or 'country' in fields or 'roles' in fields\ or 'roles' in fields or 'note' in fields\
or 'note' in fields or fields == None: or fields == None:
return self.get_movie(movie.id) return self.get_movie(movie.id)
else: else:
return movie return movie

View file

@ -49,12 +49,18 @@ class ImdbBrowser(BaseBrowser):
for cat in ['title_popular','title_exact','title_approx']: for cat in ['title_popular','title_exact','title_approx']:
if jres.has_key(cat): if jres.has_key(cat):
for m in jres[cat]: for m in jres[cat]:
tdesc = unicode(m['title_description'])
if '<a' in tdesc and '>' in tdesc:
short_description = u'%s %s'%(tdesc.split('<')[0].strip(', '), tdesc.split('>')[1].split('<')[0])
else:
short_description = tdesc.strip(', ')
#movie = self.get_movie(m['id']) #movie = self.get_movie(m['id'])
movie = Movie(m['id'],unicode(m['title'])) movie = Movie(m['id'],unicode(m['title']))
movie.other_titles = NotLoaded movie.other_titles = NotLoaded
movie.release_date = NotLoaded movie.release_date = NotLoaded
movie.duration = NotLoaded movie.duration = NotLoaded
movie.description = NotLoaded movie.short_description = short_description
movie.pitch = NotLoaded
movie.country = NotLoaded movie.country = NotLoaded
movie.note = NotLoaded movie.note = NotLoaded
movie.roles = NotLoaded movie.roles = NotLoaded
@ -75,6 +81,7 @@ class ImdbBrowser(BaseBrowser):
person.gender = NotLoaded person.gender = NotLoaded
person.nationality = NotLoaded person.nationality = NotLoaded
person.short_biography= NotLoaded person.short_biography= NotLoaded
person.short_description= unicode(p['description'])
person.roles = NotLoaded person.roles = NotLoaded
yield person yield person
@ -88,7 +95,7 @@ class ImdbBrowser(BaseBrowser):
title = NotAvailable title = NotAvailable
duration = NotAvailable duration = NotAvailable
release_date = NotAvailable release_date = NotAvailable
description = NotAvailable pitch = NotAvailable
country = NotAvailable country = NotAvailable
note = NotAvailable note = NotAvailable
other_titles = [] other_titles = []
@ -123,7 +130,7 @@ class ImdbBrowser(BaseBrowser):
country += '%s, '%c country += '%s, '%c
country = country[:-2] country = country[:-2]
if jres.has_key('plot_simple'): if jres.has_key('plot_simple'):
description = unicode(jres['plot_simple']) pitch = unicode(jres['plot_simple'])
if jres.has_key('rating') and jres.has_key('rating_count'): if jres.has_key('rating') and jres.has_key('rating_count'):
note = u'%s/10 (%s votes)'%(jres['rating'],jres['rating_count']) note = u'%s/10 (%s votes)'%(jres['rating'],jres['rating_count'])
for r in ['actor','director','writer']: for r in ['actor','director','writer']:
@ -134,7 +141,7 @@ class ImdbBrowser(BaseBrowser):
movie.other_titles = other_titles movie.other_titles = other_titles
movie.release_date = release_date movie.release_date = release_date
movie.duration = duration movie.duration = duration
movie.description = description movie.pitch = pitch
movie.country = country movie.country = country
movie.note = note movie.note = note
movie.roles = roles movie.roles = roles

View file

@ -106,6 +106,7 @@ class PersonPage(BasePage):
def get_person(self,id): def get_person(self,id):
name = NotAvailable name = NotAvailable
short_biography = NotAvailable short_biography = NotAvailable
short_description = NotAvailable
birth_place = NotAvailable birth_place = NotAvailable
birth_date = NotAvailable birth_date = NotAvailable
death_date = NotAvailable death_date = NotAvailable
@ -160,6 +161,7 @@ class PersonPage(BasePage):
person.gender = gender person.gender = gender
person.nationality = nationality person.nationality = nationality
person.short_biography = short_biography person.short_biography = short_biography
person.short_description = short_description
person.roles = roles person.roles = roles
return person return person

View file

@ -32,7 +32,7 @@ __all__ = ['Cineoob']
class MovieInfoFormatter(IFormatter): class MovieInfoFormatter(IFormatter):
MANDATORY_FIELDS = ('id', 'original_title', 'release_date', 'other_titles', 'duration', 'description', 'note', 'roles', 'country') MANDATORY_FIELDS = ('id', 'original_title', 'release_date', 'other_titles', 'duration', 'pitch', 'note', 'roles', 'country')
def format_obj(self, obj, alias): def format_obj(self, obj, alias):
result = u'%s%s%s\n' % (self.BOLD, obj.original_title, self.NC) result = u'%s%s%s\n' % (self.BOLD, obj.original_title, self.NC)
@ -53,29 +53,23 @@ class MovieInfoFormatter(IFormatter):
result += '\n%sOther titles%s\n' % (self.BOLD, self.NC) result += '\n%sOther titles%s\n' % (self.BOLD, self.NC)
for t in obj.other_titles: for t in obj.other_titles:
result += ' * %s\n' % t result += ' * %s\n' % t
if obj.description != NotAvailable: if obj.pitch != NotAvailable:
result += '\n%sDescription%s\n' % (self.BOLD, self.NC) result += '\n%sStory%s\n' % (self.BOLD, self.NC)
result += '%s'%obj.description result += '%s'%obj.pitch
return result return result
class MovieListFormatter(PrettyFormatter): class MovieListFormatter(PrettyFormatter):
MANDATORY_FIELDS = ('id', 'original_title', 'release_date', 'duration', 'note') MANDATORY_FIELDS = ('id', 'original_title', 'short_description')
def get_title(self, obj): def get_title(self, obj):
return obj.original_title return obj.original_title
def get_description(self, obj): def get_description(self, obj):
date_str = '' result = u''
if obj.release_date != NotAvailable and obj.release_date != NotLoaded: if obj.short_description != NotAvailable:
date_str = 'released: %s, '%obj.release_date.strftime('%Y-%m-%d') result = obj.short_description
duration = '' return result
if obj.duration != NotAvailable and obj.duration != NotLoaded:
duration = 'duration: %smin, '%obj.duration
note = ''
if obj.note != NotAvailable and obj.note != NotLoaded:
note = 'note: %s, '%obj.note
return ('%s %s %s' % (date_str, note, duration)).strip(', ')
def yearsago(years, from_date=None): def yearsago(years, from_date=None):
if from_date is None: if from_date is None:
@ -132,25 +126,16 @@ class PersonInfoFormatter(IFormatter):
class PersonListFormatter(PrettyFormatter): class PersonListFormatter(PrettyFormatter):
MANDATORY_FIELDS = ('id', 'name', 'real_name', 'birth_date', 'nationality', 'gender') MANDATORY_FIELDS = ('id', 'name', 'short_description')
def get_title(self, obj): def get_title(self, obj):
return obj.name return obj.name
def get_description(self, obj): def get_description(self, obj):
age = '' result = u''
if obj.birth_date != NotAvailable and obj.death_date == NotAvailable: if obj.short_description != NotAvailable:
age = 'age: %s'%num_years(obj.birth_date) result = obj.short_description
gender = '' return result
if obj.gender != NotAvailable:
gender = 'gender: %s, '%obj.gender
real_name = ''
if obj.real_name != NotAvailable:
real_name = 'real name: %s, '%obj.real_name
nationality = ''
if obj.nationality != NotAvailable:
nationality = 'nationality: %s, '%obj.nationality
return ('%s%s%s%s' % (real_name, age, nationality, gender)).strip(' ,')
class Cineoob(ReplApplication): class Cineoob(ReplApplication):
@ -276,7 +261,7 @@ class Cineoob(ReplApplication):
print >>sys.stderr, 'Movie not found: %s' % id print >>sys.stderr, 'Movie not found: %s' % id
return 3 return 3
backend.fillobj(movie, ('description','duration')) backend.fillobj(movie, ('duration'))
self.start_format() self.start_format()
self.format(movie) self.format(movie)

View file

@ -32,7 +32,8 @@ class Movie(CapBaseObject):
other_titles = Field('Titles in other countries',list) other_titles = Field('Titles in other countries',list)
release_date = DateField('Release date of the movie') release_date = DateField('Release date of the movie')
duration = IntField('Duration of the movie in minutes') duration = IntField('Duration of the movie in minutes')
description = StringField('Short description of the movie') short_description= StringField('Short description of the movie')
pitch = StringField('Short story description of the movie')
country = StringField('Origin country of the movie') country = StringField('Origin country of the movie')
note = StringField('Notation of the movie') note = StringField('Notation of the movie')
roles = Field('Lists of Persons related to the movie indexed by roles',dict) roles = Field('Lists of Persons related to the movie indexed by roles',dict)
@ -54,6 +55,7 @@ class Person(CapBaseObject):
gender = StringField('Gender of a person') gender = StringField('Gender of a person')
nationality = StringField('Nationality of a person') nationality = StringField('Nationality of a person')
short_biography = StringField('Short biography of a person') short_biography = StringField('Short biography of a person')
short_description = StringField('Short description of a person')
roles = Field('Lists of movies related to the person indexed by roles',dict) roles = Field('Lists of movies related to the person indexed by roles',dict)
def __init__(self, id, name): def __init__(self, id, name):