def test_countries(self, patched_requests_get):
     ep = EveryPolitician()
     countries = ep.countries()
     assert len(countries) == 3
     assert text_type(countries[0]) == '<Country: Åland>'
     assert text_type(countries[1]) == '<Country: Argentina>'
     assert text_type(countries[2]) == '<Country: British Virgin Islands>'
Ejemplo n.º 2
0
def main():
    ep = EveryPolitician()
    legislatures = get_legislatures(ep.countries())
    politicians = get_people(legislatures)
    memberships = get_memberships(legislatures)
    organizations = get_organizations(legislatures)
    legislative_periods = get_legislative_periods(legislatures)
    politicians = create_additional_columns_every_politician(
        politicians, memberships, organizations, legislative_periods)
    filtered_politicians = filter_politicians_for_sufficient_date(politicians)
    write_csv_s3(filtered_politicians, 'politicians', fs)
Ejemplo n.º 3
0
        return None
    return data

# auth stuff
if not consumer_key:
    raise Exception("Please set env variable: MORPH_TWITTER_CONSUMER_KEY")
if not consumer_secret:
    raise Exception("Please set env variable: MORPH_TWITTER_CONSUMER_SECRET")
token = _get_token(consumer_key, consumer_secret)
auth_header = {'Authorization': 'Bearer {token}'.format(token=token)}

ep = EveryPolitician()

ep_twitter_data = []
# get the routes to all the popolo files
for country in ep.countries():
    print('Fetching EP data for {country_name} ...'.format(country_name=country.name))
    for legislature in country.legislatures():
        # build a list of all the Twitter handles & IDs on EveryPolitician
        for person in legislature.popolo().persons:
            twitter_handles = person.twitter_all
            twitter_ids = person.identifier_values('twitter')
            # TODO this assumes identifier ordering
            # and contact detail ordering is the same! :\
            for handle, id_ in itertools.zip_longest(twitter_handles, twitter_ids):
                ep_twitter_data.append({
                    'person_id': person.id,
                    'handle': handle,
                    'twitter_id': id_,
                })
 def test_json_only_fetched_once(self, patched_requests_get):
     ep = EveryPolitician()
     ep.countries()
     ep.countries()
     assert patched_requests_get.call_count == 1
 def test_countries_from_local_file(self, patched_requests_get):
     filename = join(dirname(__file__), 'test-data',
                     'example-countries.json')
     ep = EveryPolitician(countries_json_filename=filename)
     countries = ep.countries()
     assert len(countries) == 3
Ejemplo n.º 6
0
    return data


# auth stuff
if not consumer_key:
    raise Exception("Please set env variable: MORPH_TWITTER_CONSUMER_KEY")
if not consumer_secret:
    raise Exception("Please set env variable: MORPH_TWITTER_CONSUMER_SECRET")
token = _get_token(consumer_key, consumer_secret)
auth_header = {'Authorization': 'Bearer {token}'.format(token=token)}

ep = EveryPolitician()

ep_twitter_data = []
# get the routes to all the popolo files
for country in ep.countries():
    print('Fetching EP data for {country_name} ...'.format(
        country_name=country.name))
    for legislature in country.legislatures():
        # build a list of all the Twitter handles & IDs on EveryPolitician
        for person in legislature.popolo().persons:
            twitter_handles = person.twitter_all
            twitter_ids = person.identifier_values('twitter')
            # TODO this assumes identifier ordering
            # and contact detail ordering is the same! :\
            for handle, id_ in itertools.zip_longest(twitter_handles,
                                                     twitter_ids):
                ep_twitter_data.append({
                    'person_id': person.id,
                    'handle': handle,
                    'twitter_id': id_,