2
THE currentRole ATTRIBUTE AND THE Character CLASS
3
=================================================
5
Since version 3.3, IMDbPY supports the character pages of the IMDb
6
database; this required some substantial changes to how actors'
7
and acresses' roles were handled.
8
So far, only the "http", "httpThin" and "mobile" data access systems
9
can manage the character pages.
11
The currentRole instance attribute can be found in every instance
12
of Person, Movie and Character classes, even if actually the Character
15
The currentRole of a Person object is set to a Character instance,
16
inside a list of person who acted in a given movie.
17
The currentRole of a Movie object is set to a Character instance,
18
inside a list of movies played be given person.
19
The currentRole of a Movie object is set to a Person instance,
20
inside a list of movies in which a given character was portrayed.
23
movie['cast'][0].currentRole -> a Character object.
27
person['actor'][0].currentRole -> a Character object.
31
character['filmography'][0].currentRole -> a Person object.
35
The roleID attribute can be used to access/set the characterID
36
or personID instance attribute of the current currentRole.
37
Building Movie or Person objects, you can pass the currentRole
38
parameter and the roleID parameter (to set the ID).
39
The currentRole parameter can be an object (Character or Person),
40
an unicode string (in which case a Character or Person object is
41
automatically instanced) or a list of objects or strings (to
42
handle multiple characters played by the same actor/actress in
43
a movie, or character played by more then a single actor/actress
46
Anyway, currentRole objects (Character or Person instances) can
47
be pretty-printed easily: calling unicode(CharacterOrPersonObject)
48
will return a good-old-unicode string, like expected in the previous
55
To help getting the required information from Movie, Person and
56
Character objects, in the "helpers" module there's a new factory
57
function, makeObject2Txt, which can be used to create your
58
pretty-printing function.
59
It takes some optional parameters: movieTxt, personTxt, characterTxt;
60
in these strings %(value)s items are replaced with object['value'] or
61
with obj.value (if the first is not present).
65
myPrint = imdb.helpers.makeObject2Txt(personTxt=u'%(name)s ... %(currentRole)s')
67
m = i.get_movie('0057012')
70
# The output will be something like:
71
Peter Sellers ... Group Captain Lionel Mandrake / President Merkin Muffley / Dr. Strangelove
74
Portions of the formatting string can be stripped conditionally: if
75
the specified condition is false, they will be cancelled.
78
myPrint = imdb.helpers.makeObject2Txt(personTxt='<if personID><a href=/person/%(personID)s></if personID>%(long imdb name)s<if personID></a></if personID><if currentRole> ... %(currentRole)s<if notes> %(notes)s</if notes></if currentRole>'
81
Another useful argumento is 'applyToValues': if set to a function,
82
it will be applied to every value before the substitution; it can
83
be useful to format strings for html output.