Commit f87a8a68 authored by Julien Veyssier's avatar Julien Veyssier Committed by Romain Bignon

[cineoob] give roles informations in persons_in_common and movies_in_common,...

[cineoob] give roles informations in persons_in_common and movies_in_common, imdb and allocine adapted
parent 372da143
......@@ -190,7 +190,8 @@ class AllocineBrowser(Browser):
for cast in jres['castMember']:
if cast['activity']['$'] not in roles:
roles[cast['activity']['$']] = []
roles[cast['activity']['$']].append(cast['person']['name'])
person_to_append = (u'%s'%cast['person']['code'], cast['person']['name'])
roles[cast['activity']['$']].append(person_to_append)
movie = Movie(id, title)
movie.other_titles = other_titles
......@@ -277,7 +278,8 @@ class AllocineBrowser(Browser):
pyear = '????'
if 'productionYear' in m['movie']:
pyear = m['movie']['productionYear']
roles[m['activity']['$']].append(u'(%s) %s' % (pyear, m['movie']['originalTitle']))
movie_to_append = (u'%s' % (m['movie']['code']), u'(%s) %s' % (pyear, m['movie']['originalTitle']))
roles[m['activity']['$']].append(movie_to_append)
person = Person(id, name)
......
......@@ -157,7 +157,7 @@ class ImdbBrowser(Browser):
note = u'%s/10 (%s votes)' % (jres['imdbRating'], jres['imdbVotes'])
for r in ['Actors', 'Director', 'Writer']:
if '%s' % r in jres.keys():
roles['%s' % r] = jres['%s' % r].split(', ')
roles['%s' % r] = [('N/A',e) for e in jres['%s' % r].split(', ')]
movie = Movie(id, title)
movie.other_titles = other_titles
......
......@@ -206,7 +206,7 @@ class PersonPage(Page):
category = role_div.attrib.get('data-category')
for infos in self.parser.select(self.document.getroot(), 'div#filmography > div.filmo-category-section > div'):
if category in infos.attrib.get('id'):
roles[role].append(infos.text_content().replace('\n', ' ').strip())
roles[role].append(('N/A',infos.text_content().replace('\n', ' ').strip()))
return roles
def iter_movies(self, role_filter=None):
......
......@@ -59,8 +59,8 @@ class MovieInfoFormatter(IFormatter):
result += '\n%sRelated persons%s\n' % (self.BOLD, self.NC)
for role, lpersons in obj.roles.items():
result += ' -- %s\n' % role
for name in lpersons:
result += ' * %s\n' % name
for person in lpersons:
result += ' * %s\n' % person[1]
if not empty(obj.other_titles):
result += '\n%sOther titles%s\n' % (self.BOLD, self.NC)
for t in obj.other_titles:
......@@ -143,7 +143,7 @@ class PersonInfoFormatter(IFormatter):
for role, lmovies in obj.roles.items():
result += ' -- %s\n' % role
for movie in lmovies:
result += ' * %s\n' % movie
result += ' * %s\n' % movie[1]
if not empty(obj.short_biography):
result += '\n%sShort biography%s\n' % (self.BOLD, self.NC)
result += '%s' % obj.short_biography
......@@ -250,6 +250,13 @@ class Cineoob(ReplApplication):
inter = list(set(lid1) & set(lid2))
for common in inter:
movie = self.get_object(common, 'get_movie', caps=CapCinema)
role1 = movie.get_role_by_person_id(person1.id)
if not role1:
role1 = movie.get_role_by_person_name(person1.name)
role2 = movie.get_role_by_person_id(person2.id)
if not role2:
role2 = movie.get_role_by_person_name(person2.name)
movie.short_description = '%s as %s ; %s as %s'%(person1.name, role1, person2.name, role2)
if movie:
self.cached_format(movie)
......@@ -283,6 +290,13 @@ class Cineoob(ReplApplication):
inter = list(set(lid1) & set(lid2))
for common in inter:
person = self.get_object(common, 'get_person', caps=CapCinema)
role1 = person.get_role_by_movie_id(movie1.id)
if not role1:
role1 = person.get_role_by_movie_title(movie1.original_title)
role2 = person.get_role_by_movie_id(movie2.id)
if not role2:
role2 = person.get_role_by_movie_title(movie2.original_title)
person.short_description = '%s in %s ; %s in %s'%(role1, movie1.original_title, role2, movie2.original_title)
self.cached_format(person)
def do_info_movie(self, id):
......
......@@ -46,6 +46,18 @@ class Movie(BaseObject):
BaseObject.__init__(self, id)
self.original_title = original_title
def get_role_by_person_name(self,name):
for role in self.roles.keys():
if name.lower() in [person[1].lower() for person in self.roles[role]]:
return role
return None
def get_role_by_person_id(self,id):
for role in self.roles.keys():
if id in [person[0] for person in self.roles[role]]:
return role
return None
class Person(BaseObject):
"""
......@@ -68,6 +80,20 @@ class Person(BaseObject):
BaseObject.__init__(self, id)
self.name = name
def get_role_by_movie_title(self,title):
for role in self.roles.keys():
for mt in [movie[1] for movie in self.roles[role]]:
# title we have is included ?
if title.lower() in mt.lower():
return role
return None
def get_role_by_movie_id(self,id):
for role in self.roles.keys():
if id in [movie[0] for movie in self.roles[role]]:
return role
return None
class CapCinema(Capability):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment