cineoob handling dates

This commit is contained in:
Julien Veyssier 2013-03-04 14:12:35 +01:00
commit efaee3a661
3 changed files with 17 additions and 14 deletions

View file

@ -30,13 +30,18 @@ __all__ = ['MoviePage','PersonPage','MovieCrewPage']
class MoviePage(BasePage): class MoviePage(BasePage):
''' Page describing a movie, only used to go on the MovieCrewPage
'''
def iter_persons(self,id): def iter_persons(self,id):
self.browser.location('http://www.imdb.com/title/%s/fullcredits'%id) self.browser.location('http://www.imdb.com/title/%s/fullcredits'%id)
assert self.browser.is_on_page(MovieCrewPage) assert self.browser.is_on_page(MovieCrewPage)
for p in self.browser.page.iter_persons(): for p in self.browser.page.iter_persons():
yield p yield p
class MovieCrewPage(BasePage): class MovieCrewPage(BasePage):
''' Page listing all the persons related to a movie
'''
def iter_persons(self): def iter_persons(self):
tables = self.parser.select(self.document.getroot(),'table.cast') tables = self.parser.select(self.document.getroot(),'table.cast')
if len(tables) > 0: if len(tables) > 0:
@ -48,6 +53,9 @@ class MovieCrewPage(BasePage):
class PersonPage(BasePage): class PersonPage(BasePage):
''' Page giving informations about a person
It is used to build a Person instance and to get the movie list related to a person
'''
def get_person(self,id): def get_person(self,id):
name = NotAvailable name = NotAvailable
biography = NotAvailable biography = NotAvailable
@ -80,7 +88,6 @@ class PersonPage(BasePage):
person.gender = gender person.gender = gender
person.nationality = nationality person.nationality = nationality
person.biography = biography person.biography = biography
person.awards = ["aw1","aw2"]
person.roles = {} person.roles = {}
return person return person

View file

@ -98,16 +98,17 @@ def num_years(begin, end=None):
return num_years return num_years
class PersonInfoFormatter(IFormatter): class PersonInfoFormatter(IFormatter):
MANDATORY_FIELDS = ('id', 'name', 'real_name', 'birth_date', 'birth_place', 'gender', 'nationality', 'biography', 'awards','roles') MANDATORY_FIELDS = ('id', 'name', 'real_name', 'birth_date', 'birth_place', 'gender', 'nationality', 'biography', 'roles')
def format_obj(self, obj, alias): def format_obj(self, obj, alias):
result = u'%s%s%s\n' % (self.BOLD, obj.name, self.NC) result = u'%s%s%s\n' % (self.BOLD, obj.name, self.NC)
result += 'ID: %s\n' % obj.fullid result += 'ID: %s\n' % obj.fullid
result += 'Real name: %s\n' % obj.real_name result += 'Real name: %s\n' % obj.real_name
result += 'Birth date: %s\n' % obj.birth_date
if obj.birth_date != NotAvailable: if obj.birth_date != NotAvailable:
result += 'Birth date: %s\n' % obj.birth_date.strftime('%Y-%m-%d')
age = num_years(obj.birth_date) age = num_years(obj.birth_date)
else: else:
result += 'Birth date: %s\n' % obj.birth_date
age = NotAvailable age = NotAvailable
result += 'Age: %s\n' % age result += 'Age: %s\n' % age
result += 'Birth place: %s\n' % obj.birth_place result += 'Birth place: %s\n' % obj.birth_place
@ -119,10 +120,6 @@ class PersonInfoFormatter(IFormatter):
result += ' -- %s\n' % role result += ' -- %s\n' % role
for movie in lmovies: for movie in lmovies:
result += ' * %s\n' % movie.original_title result += ' * %s\n' % movie.original_title
if obj.awards:
result += '\n%sAwards%s\n' % (self.BOLD, self.NC)
for a in obj.awards:
result += ' * %s\n' % a
result += '\n%sBiography%s\n' % (self.BOLD, self.NC) result += '\n%sBiography%s\n' % (self.BOLD, self.NC)
result += '%s'%obj.biography result += '%s'%obj.biography
return result return result
@ -170,7 +167,7 @@ class Cineoob(ReplApplication):
def do_info_movie(self, id): def do_info_movie(self, id):
""" """
info_movie ID info_movie movie_ID
Get information about a movie. Get information about a movie.
""" """
@ -186,7 +183,7 @@ class Cineoob(ReplApplication):
def do_info_person(self, id): def do_info_person(self, id):
""" """
info_person ID info_person person_ID
Get information about a person. Get information about a person.
""" """
@ -202,7 +199,7 @@ class Cineoob(ReplApplication):
def do_search_movie(self, pattern): def do_search_movie(self, pattern):
""" """
search [PATTERN] search_movie [PATTERN]
Search movies. Search movies.
""" """
@ -217,7 +214,7 @@ class Cineoob(ReplApplication):
def do_search_person(self, pattern): def do_search_person(self, pattern):
""" """
search [PATTERN] search_person [PATTERN]
Search persons. Search persons.
""" """
@ -232,7 +229,7 @@ class Cineoob(ReplApplication):
def do_casting(self, movie_id): def do_casting(self, movie_id):
""" """
casting movie_id casting movie_ID
List persons related to a movie. List persons related to a movie.
""" """
@ -248,7 +245,7 @@ class Cineoob(ReplApplication):
def do_filmography(self, person_id): def do_filmography(self, person_id):
""" """
filmography person_id filmography person_ID
List movies of a person. List movies of a person.
""" """

View file

@ -53,7 +53,6 @@ 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')
biography = StringField('Short biography of a person') biography = StringField('Short biography of a person')
awards = Field('Awards won by the person',list)
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):