Skip to content

Instantly share code, notes, and snippets.

@mhl
Last active October 28, 2016 18:27
Show Gist options
  • Save mhl/814de8331632eede31efea164b8a3a2c to your computer and use it in GitHub Desktop.
Save mhl/814de8331632eede31efea164b8a3a2c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import unicode_literals
from datetime import date
from itertools import islice
from everypolitician import EveryPolitician
import matplotlib.pyplot as plt
COUNTRIES_LIMIT = None
ep = EveryPolitician()
country_house_pairs = (
(c, l)
for c in ep.countries()
for l in c.legislatures()
)
if COUNTRIES_LIMIT:
country_house_pairs = islice(country_house_pairs, COUNTRIES_LIMIT)
def get_current_term(popolo):
for event in popolo.events:
if event.classification != 'legislative period':
continue
if not event.current:
continue
return event
def get_people_in_term(popolo, term):
people = set()
for membership in popolo.memberships:
if membership.legislative_period_id != current_term.id:
continue
if not membership.current:
continue
person = membership.person
if person.death_date:
continue
people.add(person)
return people
data = []
for country, house in country_house_pairs:
name = '{0}, {1}'.format(country.name, house.name)
print "=====", name
popolo = house.popolo()
approx_ages = []
current_term = get_current_term(popolo)
if not current_term:
print "No current term found"
continue
for person in get_people_in_term(popolo, current_term):
birth_date = person.birth_date
if not birth_date:
continue
approx_birth_date = birth_date.midpoint_date
approx_age = (date.today() - approx_birth_date).days / 365.25
# Exclude anyone who seems to be absurdly young, since that's
# probably a data error:
if approx_age < 10:
msg = "Excluding {0} who appears to be roughly {1} years old " \
"- probably a data error"
print msg.format(person.name, approx_age)
continue
approx_ages.append(approx_age)
if approx_ages:
n = len(approx_ages)
if n < 10:
print("Ignoring because there are less than 10 birth dates")
continue
mean_age_in_days = sum(approx_ages) / float(n)
data.append((mean_age_in_days, n, name))
else:
print "No dates of birth found"
data.sort(key=lambda t: t[0])
x_values = range(len(data))
plt.axis([-1, len(data), 0, 200])
plt.ylabel('Mean age of representatives in years')
plt.plot(x_values, [t[0] for t in data], 'bo')
for x, t in enumerate(data):
y, n, name = t
label = '{0} ({1})'.format(name, n)
plt.annotate(
label,
xy=(x, y),
xytext=(0, 20),
rotation=90,
textcoords = 'offset points', ha = 'right', va = 'bottom',
)
plt.show()
everypolitician==0.0.7
requests==2.11.1
six==1.10.0
(youngest-parliament) # mark@syrah:~/youngest-parliament (master)
./find-youngest-parliament.py
===== Abkhazia, People's Assembly
Ignoring because there are less than 10 birth dates
===== Afghanistan, Wolesi Jirga
No current term found
===== Albania, Kuvendi
===== Alderney, States
No dates of birth found
===== Algeria, People's National Assembly
Ignoring because there are less than 10 birth dates
===== American Samoa, House of Representatives
No dates of birth found
===== Andorra, Consell General
===== Angola, National Assembly
No dates of birth found
===== Anguilla, House of Assembly
No dates of birth found
===== Antigua and Barbuda, House of Representatives
Ignoring because there are less than 10 birth dates
===== Argentina, Cámara de Diputados
===== Argentina, Cámara de Senadores
===== Armenia, National Assembly
===== Aruba, Estates of Aruba
Ignoring because there are less than 10 birth dates
===== Australia, House of Representatives
===== Australia, Senate
===== Austria, Nationalrat
===== Azerbaijan, National Assembly
===== Bahamas, House of Assembly
===== Bahrain, Council of Representatives
No dates of birth found
===== Bangladesh, Jatiyo Sangshad
===== Barbados, House of Assembly
No dates of birth found
===== Belarus, House of Representatives
===== Belgium, Chamber of Representatives
===== Belize, House of Representatives
Ignoring because there are less than 10 birth dates
===== Benin, Assemblée Nationale
No dates of birth found
===== Bermuda, Parliament
No dates of birth found
===== Bhutan, National Assembly
No dates of birth found
===== Bolivia, Chamber of Deputies
Ignoring because there are less than 10 birth dates
===== Bosnia and Herzegovina, House of Representatives
No dates of birth found
===== Botswana, National Assembly
Ignoring because there are less than 10 birth dates
===== Brazil, Chamber of Deputies
===== British Virgin Islands, House of Assembly
Ignoring because there are less than 10 birth dates
===== British Virgin Islands, Legislative Council
No current term found
===== Brunei, Legislative Council of Brunei
No current term found
===== Bulgaria, National Assembly
No current term found
===== Burkina Faso, Assemblée Nationale
No dates of birth found
===== Burundi, Assemblée nationale
No dates of birth found
===== Cabo Verde, Assembleia Nacional
No dates of birth found
===== Cambodia, National Assembly
===== Cameroon, Assemblée Nationale
Excluding NSOSIE EBAH Susana épse Okpu who appears to be roughly 1.82340862423 years old - probably a data error
Excluding ENOW ETOUNDI who appears to be roughly 1.82340862423 years old - probably a data error
Excluding jean-Bertrand NDONGO ESSOMBA who appears to be roughly -29.8097193703 years old - probably a data error
===== Cameroon, Sénat
No dates of birth found
===== Canada, House of Commons
===== Cayman Islands, Legislative Assembly
No dates of birth found
===== Chad, Assemblée Nationale
No dates of birth found
===== Chile, National Congress
===== China, National People’s Congress
No dates of birth found
===== Colombia, Cámara de Representantes
===== Colombia, Senado
===== Comoros, Assembly of the Union
No dates of birth found
===== Congo-Brazzaville, Assemblee Nationale
No dates of birth found
===== Congo-Kinshasa (DRC), National Assembly
Ignoring because there are less than 10 birth dates
===== Cook Islands, Parliament
Ignoring because there are less than 10 birth dates
===== Costa Rica, Legislative Assembly
Ignoring because there are less than 10 birth dates
===== Croatia, Sabor
No current term found
===== Curaçao, Estates of Curaçao
No dates of birth found
===== Cyprus, House of Representatives
===== Czech Republic, Chamber of Deputies
===== Côte d'Ivoire, National Assembly
No dates of birth found
===== Denmark, Folketing
===== Djibouti, National Assembly
No dates of birth found
===== Dominica, House of Assembly
No dates of birth found
===== Dominican Republic, Chamber of Deputies
No current term found
===== Ecuador, National Assembly
===== Egypt, Parliament
===== El Salvador, Legislative Assembly
No dates of birth found
===== Estonia, Riigikogu
===== Falkland Islands, Legislative Assembly
Ignoring because there are less than 10 birth dates
===== Faroe Islands, Løgting
===== Fiji, Parliament
Ignoring because there are less than 10 birth dates
===== Finland, Eduskunta
===== France, Assemblée nationale
===== French Polynesia, Assembly
===== Gabon, Assemblée nationale
Ignoring because there are less than 10 birth dates
===== Gambia, National Assembly
===== Georgia, Parliament of Georgia
No current term found
===== Germany, Bundestag
===== Ghana, Parliament
Excluding Joseph Bipoba Naabu who appears to be roughly 3.64134154689 years old - probably a data error
===== Gibraltar, Parliament
No current term found
===== Greece, Hellenic Parliament
Excluding Syrigos Antonios who appears to be roughly 0.0191649555099 years old - probably a data error
===== Greenland, Inatsisartut
===== Grenada, House of Representatives
No dates of birth found
===== Guam, Parliament
Ignoring because there are less than 10 birth dates
===== Guatemala, Congress
Excluding Édgar Armando Sandoval Trigueros who appears to be roughly 0.772073921971 years old - probably a data error
Excluding Oscar Rolando Corleto Rivera who appears to be roughly 4.78576317591 years old - probably a data error
Excluding Alsider Antonio Arias Rodríguez who appears to be roughly 0.774811772758 years old - probably a data error
Excluding Julio Ixcamey Velásquez who appears to be roughly 0.772073921971 years old - probably a data error
Excluding Mike Ottoniel Mérida Reyes who appears to be roughly 0.774811772758 years old - probably a data error
Excluding Juan Ramón Lau Quan who appears to be roughly 0.772073921971 years old - probably a data error
Excluding María Cristina Quinto García who appears to be roughly 0.772073921971 years old - probably a data error
Excluding Ovidio Joel Domingo Bámaca who appears to be roughly 0.772073921971 years old - probably a data error
Excluding Vivian Beatriz Preciado Navarijo who appears to be roughly 0.772073921971 years old - probably a data error
Excluding Karla Andrea Martínez Hernández who appears to be roughly 0.774811772758 years old - probably a data error
Excluding Héctor Melvyn Caná Rivera who appears to be roughly 0.774811772758 years old - probably a data error
Excluding Julio Antonio Juárez Ramírez who appears to be roughly 0.772073921971 years old - probably a data error
Excluding Julián Tesucún Tesucún who appears to be roughly 3.9151266256 years old - probably a data error
Excluding Erick René Lainfiesta Cáceres who appears to be roughly 0.774811772758 years old - probably a data error
Excluding Edgar Raúl Reyes Lee who appears to be roughly 0.772073921971 years old - probably a data error
Excluding María Stella Alonzo Bolaños who appears to be roughly 0.774811772758 years old - probably a data error
Excluding Milton Francisco Guerra Calderón who appears to be roughly 0.788501026694 years old - probably a data error
Excluding Marleni Lineth Matías Santiago who appears to be roughly 0.774811772758 years old - probably a data error
Excluding Marco Antonio Lemus Salguero who appears to be roughly 3.76454483231 years old - probably a data error
Excluding Claude Harmelin de León who appears to be roughly 0.774811772758 years old - probably a data error
Excluding Víctor Manuel Estrada Orellana who appears to be roughly 0.774811772758 years old - probably a data error
Excluding Carlos Enrique López Maldonado who appears to be roughly 0.772073921971 years old - probably a data error
Excluding José Arturo Martínez Dell who appears to be roughly 0.772073921971 years old - probably a data error
Excluding Herber Armando Melgar Padilla who appears to be roughly 0.175222450376 years old - probably a data error
Excluding Johnatan Abel Cardona Arreaga who appears to be roughly 0.774811772758 years old - probably a data error
Excluding Pedro Méndez Carreto who appears to be roughly 0.772073921971 years old - probably a data error
===== Guernsey, States
Ignoring because there are less than 10 birth dates
===== Guinea-Bissau, National People's Assembly
No dates of birth found
===== Guyana, National Assembly
No dates of birth found
===== Haiti, Chamber of Deputies
No current term found
===== Honduras, National Congress
Ignoring because there are less than 10 birth dates
===== Hong Kong, Legislative Council
===== Hungary, Országgyűlés
===== Iceland, Alþingi
===== India, Lok Sabha
===== Indonesia, Dewan Perwakilan Rakyat
===== Iran, Majles
Ignoring because there are less than 10 birth dates
===== Iraq, Council of Representatives
===== Ireland, Dáil Éireann
===== Isle of Man, House of Keys
===== Israel, Knesset
No current term found
===== Italy, House of Representatives
===== Italy, Senate
===== Jamaica, House of Representatives
===== Japan, Shūgiin
===== Jersey, States
No dates of birth found
===== Jordan, House of Representatives
Ignoring because there are less than 10 birth dates
===== Kazakhstan, Mazhilis
No dates of birth found
===== Kenya, National Assembly
===== Kiribati, Parliament
No current term found
===== Kosovo, Kuvendit
Ignoring because there are less than 10 birth dates
===== Kuwait, National Assembly
Ignoring because there are less than 10 birth dates
===== Kyrgyzstan, Supreme Council
Ignoring because there are less than 10 birth dates
===== Laos, National Assembly
No current term found
===== Latvia, Saeima
===== Lebanon, Parliament
===== Lesotho, National Assembly
Ignoring because there are less than 10 birth dates
===== Liberia, House of Representatives
No dates of birth found
===== Libya, House of Representatives
No dates of birth found
===== Liechtenstein, Landtag
===== Lithuania, Seimas
===== Luxembourg, Chamber of Deputies
===== Macao, Legislative Assembly
===== Macedonia, Sobranie
Ignoring because there are less than 10 birth dates
===== Madagascar, National Assembly
No dates of birth found
===== Malawi, National Assembly
No dates of birth found
===== Malaysia, Dewan Rakyat
===== Maldives, Majlis
No dates of birth found
===== Mali, National Assembly
No dates of birth found
===== Malta, Parliament
===== Marshall Islands, Nitijela
No current term found
===== Mauritania, National Assembly
No dates of birth found
===== Mauritius, National Assembly
No dates of birth found
===== Mexico, Chamber of Deputies
Ignoring because there are less than 10 birth dates
===== Micronesia, Congress
Ignoring because there are less than 10 birth dates
===== Moldova, Parlament
===== Monaco, National Council
No dates of birth found
===== Mongolia, State Great Khural
===== Montenegro, Skupština
No current term found
===== Montserrat, Legislative Assembly
No dates of birth found
===== Morocco, House of Representatives
No dates of birth found
===== Mozambique, Assembleia da República
No dates of birth found
===== Myanmar, House of Representatives
No current term found
===== Nagorno-Karabakh, National Assembly
===== Namibia, National Assembly
===== Namibia, National Council
No dates of birth found
===== Nauru, Parliament
Ignoring because there are less than 10 birth dates
===== Nepal, Constituent Assembly
===== Netherlands, Tweede Kamer
===== New Caledonia, Congress
===== New Zealand, New Zealand Parliament
===== Nicaragua, National Assembly
No dates of birth found
===== Niger, Assemblée nationale
No dates of birth found
===== Nigeria, National Assembly
No dates of birth found
===== Niue, Assembly
Ignoring because there are less than 10 birth dates
===== Norfolk Island, Legislative Assembly
No current term found
===== North Korea, Supreme People’s Assembly
===== Northern Cyprus, Assembly of the Republic
===== Northern Ireland, Northern Ireland Assembly
===== Northern Mariana Islands, House of Representatives
No dates of birth found
===== Norway, Storting
===== Oman, Majlis al-Shura
No current term found
===== Pakistan, National Assembly
===== Palau, House of Delegates
No dates of birth found
===== Panama, Asamblea Nacional
No dates of birth found
===== Papua New Guinea, National Parliament
Ignoring because there are less than 10 birth dates
===== Paraguay, Chamber of Deputies
No dates of birth found
===== Peru, Congress
No current term found
===== Philippines, House of Representatives
===== Pitcairn, Island Council
No dates of birth found
===== Poland, Sejm
===== Portugal, Assembleia da República
===== Puerto Rico, House of Representatives
===== Romania, Chamber of Deputies
===== Russia, Duma
===== Rwanda, Chamber of Deputies
No dates of birth found
===== Saint Barthélemy, Territorial Council
Ignoring because there are less than 10 birth dates
===== Saint Helena, Legislative Council
No dates of birth found
===== Saint Kitts and Nevis, National Assembly
Ignoring because there are less than 10 birth dates
===== Saint Lucia, House of Assembly
No current term found
===== Saint Martin, Territorial Council
Ignoring because there are less than 10 birth dates
===== Saint Pierre and Miquelon, Territorial Council
Ignoring because there are less than 10 birth dates
===== Saint Vincent and the Grenadines, House of Assembly
No current term found
===== Samoa, Fono
No current term found
===== San Marino, Grand and General Council
===== Sark, Chief Pleas
No dates of birth found
===== Saudi Arabia, Shura Council
No dates of birth found
===== Scotland, Scottish Parliament
===== Senegal, National Assembly
Ignoring because there are less than 10 birth dates
===== Serbia, National Assembly
===== Seychelles, National Assembly
Excluding Hon. Nichole Barbe who appears to be roughly 1.61533196441 years old - probably a data error
===== Sierra Leone, Parliament
No dates of birth found
===== Singapore, Parliament
===== Sint Maarten, Estates
No dates of birth found
===== Slovakia, National Council
===== Slovenia, Državni zbor
Excluding Mag. Julijana Bizjak Mlakar who appears to be roughly 0.139630390144 years old - probably a data error
===== Solomon Islands, National Parliament
===== Somalia, House of the People
No dates of birth found
===== Somaliland, House of Representatives
No dates of birth found
===== South Africa, National Assembly
===== South Korea, National Assembly
===== South Ossetia, Parliament
No dates of birth found
===== South Sudan, National Legislative Assembly
No dates of birth found
===== Spain, Congreso de los Diputados
===== Sri Lanka, Parliament
===== Suriname, National Assembly
===== Swaziland, House of Assembly
No dates of birth found
===== Sweden, Riksdag
===== Switzerland, National Council
===== Syria, People’s Council
===== Taiwan, Legislative Yuan
===== Tajikistan, Assembly of Representatives
No dates of birth found
===== Tanzania, National Assembly
Excluding Prof. Jumanne Abdallah Maghembe who appears to be roughly -934.800821355 years old - probably a data error
===== Thailand, National Legislative Assembly
Ignoring because there are less than 10 birth dates
===== Timor Leste, Parlamento
No dates of birth found
===== Togo, National Assembly
Ignoring because there are less than 10 birth dates
===== Tonga, Legislative Assembly
No dates of birth found
===== Transnistria, Supreme Council
No dates of birth found
===== Trinidad and Tobago, House of Representatives
No dates of birth found
===== Trinidad and Tobago, Senate
No dates of birth found
===== Tunisia, Assembly of the Representatives of the People
===== Turkey, Grand National Assembly
===== Turkmenistan, Mejlis
No dates of birth found
===== Turks and Caicos Islands, House of Assembly
Ignoring because there are less than 10 birth dates
===== Tuvalu, Parliament
Ignoring because there are less than 10 birth dates
===== US Virgin Islands, Legislature
No dates of birth found
===== Uganda, Parliament
===== Ukraine, Verkhovna Rada
===== United Arab Emirates, Federal National Council
No current term found
===== United Kingdom, House of Commons
===== United States of America, House of Representatives
===== United States of America, Senate
===== Uruguay, Chamber of Deputies
===== Uzbekistan, Legislative Chamber
===== Vanuatu, Parliament
Ignoring because there are less than 10 birth dates
===== Vatican City, Pontifical Commission
Ignoring because there are less than 10 birth dates
===== Venezuela, National Assembly
===== Vietnam, National Assembly
No current term found
===== Wales, National Assembly for Wales
===== Wallis and Futuna, Territorial Assembly
Ignoring because there are less than 10 birth dates
===== Yemen, House of Representatives
No dates of birth found
===== Zambia, National Assembly
Excluding Misheck Mutelo who appears to be roughly 5.08145106092 years old - probably a data error
===== Zimbabwe, House of Assembly
===== Zimbabwe, Senate
No dates of birth found
===== Åland, Lagting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment