andylolz/everypolitician-popolo

Parse EveryPolitician-flavoured Popolo data, and navigate it with PHP

0.0.3 2016-12-13 11:02 UTC

This package is not auto-updated.

Last update: 2024-11-09 20:50:55 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

This is a port of the Python package everypolitician-popolo-python to PHP, which itself is a port of the Ruby gem everypolitician-popolo to Python.

Install

Via Composer

$ composer require andylolz/everypolitician-popolo

Usage

You can download a Popolo file manually from EveryPolitician.

The following example uses Åland Lagting (which is the legislature of the Åland islands, available as JSON data from the EveryPolitician page for Åland).

First you'll need to require the library and read in a file from disk.

use \EveryPolitician\EveryPoliticianPopolo\Popolo;
$popolo = Popolo::fromFilename('ep-popolo-v1.0.json');

All Popolo classes used by EveryPolitician are implemented:

There are methods defined for each property on a class, e.g. for a Person:

count($popolo->persons); // 60
$person = $popolo->persons->first;
echo $person->id; // e3aab23e-a883-4763-be0d-92e5936024e2
echo $person->name; // Aaltonen Carina
echo $person->image; // http://www.lagtinget.ax/files/aaltonen_carina.jpg
echo $person->wikidata; // Q4934081

You can also find individual records or collections based on their attributes:

echo $popolo->persons->get(["name" => "Aaltonen Carina"]); // <Person: Aaltonen Carina>

$organizations = $popolo->organizations->filter(["classification" => "party"]);
foreach ($organizations as $organization) {
    echo $organization;
}
// <Organization: Liberalerna>
// <Organization: Liberalerna på Åland r.f.>
// <Organization: Moderat Samling>
// <Organization: Moderat Samling på Åland r.f.>
// <Organization: Moderat samling>
// <Organization: Moderaterna på Åland>
// <Organization: Obunden Samling>
// <Organization: Obunden Samling på Åland>
// <Organization: Ålands Framtid>
// <Organization: Ålands Socialdemokrater>
// <Organization: Ålands framtid>
// <Organization: Ålands socialdemokrater>
// <Organization: Åländsk Center>
// <Organization: Åländsk Center r.f.>
// <Organization: Åländsk Demokrati>
// <Organization: Åländsk center>

Change log

Please see CHANGELOG for information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Credits

License

The MIT License (MIT). Please see License File for more information.