Parties and Polls¶
Core features of mapache.
Creating a party¶
-
class
mapache.core.Party(name, logo_url, short_name=None, full_name=None, extra_names=None, thumbnail_url=None)[source]¶ Implements a political party.
-
__init__(name, logo_url, short_name=None, full_name=None, extra_names=None, thumbnail_url=None)[source]¶ Create political party.
Parameters: - name (str) – Name of the party. The preferred name to be used,
although other names can be provided. If
short_nameis not indicated,namewill be used to crate an abbreviation. - picture_url (Optional[str]) – url to the party logo, the color for the party will be generated from the image.
- short_name (Optional[List[str]]) – Abbreviation of the party name to
be displayed when there is no space for
name. Maximum of 7 characters. - full_name (Optional[str]) – Official, full name of the part
- extra_names (Optional[List[str]]) – Any number of extra names of the party to help matching the party to polls (eg. names in different languages).
- name (str) – Name of the party. The preferred name to be used,
although other names can be provided. If
-
__weakref__¶ list of weak references to the object (if defined)
-
add_to_coalition(party)[source]¶ Consider this party a coalition and add a party to it.
When the first party is added this party becomes a coalition. The parties in the coalition will be used to match the party with polls if the opposite is not specified.
Parameters: party (mapache.Party) – party to be added to the coalition
-
get_all_names()[source]¶ All names of the party.
Returns: all the names of the party (long, short, extra...) Return type: (list)
-
get_logo(url)[source]¶ Current logo of the party.
Returns: Current logo of the party Return type: PIL.Image
-
get_thumbnail(url)[source]¶ Current thumbnail of the party.
Returns: Current thumbnail of the party Return type: PIL.Image
-
match(party_name)[source]¶ Evaluate how well a name matches this party.
mapache.core._levenshtein_distance is used for the comparison. All names of the party are used in the comparison.
Parameters: party_name (str) – name to be evaluated
-
set_logo(url)[source]¶ Set the logo and updates the party color.
The image is download from
urland the color of the partyself.coloris updated to the principal color of the imageParameters: url (str) – url to a image with the logo of the party
-
set_thumbnail(url=None)[source]¶ Set the thumbnail of the party.
The size of the thumbnail will be 80x80 and squared images are preferred. If no url is provided the logo of the party will be used as the thumbnail.
Parameters: url (Optional[str]) – url to a image with the small logo of the party
-