Skip to content

Convert data from Dutch elections in EML XML files to a CSV file that has data per party per stemburea.

License

Notifications You must be signed in to change notification settings

kroncrv/electiontool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

electiontool.py

Command line utility to convert data from Dutch elections in EML XML files to a CSV file that has data per party per stembureau and/or per candidate. Written in Python 3.

Installation

You'll need to have the packages dataknead, xmltodict and dpath installed.

You can also use poetry to install dependencies and create a virtual environment

poetry install
poetry run ./electiontool.py

Examples

Parse all XML files in a directory called data and output as a CSV file called ps2019.csv:

./electiontool.py -i data -o ps2019.csv

Also add percentages aside from absolute votes

./electiontool.py -i data -o ps2019.csv --add-percentages

Parse one single XML file to a csv file

./electiontool.py -i terschelling.xml -o terschelling.csv

For some elections (like the Waterschappen), it can be useful to add the 'ContestName' to the output as well

./electiontool.py -i data -o ps2019.csv --add-contestname

Output results with votes per candidate (note that this might lead to large CSV files). A couple of columns are removed to reduce the file size. Note that you manually need to match candidate identifiers with the names, because these are not available in the original XML files.

./electiontool.py -i data -o ps2019.csv --output-structure candidates

Troubleshooting

  • Before opening an issue, try running your command with the -v (verbose) switch, because this will give you more debug information.

All options

You'll get this output when running electiontool.py -h.

usage: electiontool.py [-h] [--add-contestname] [--add-percentages] -i INPUT
                       [-if {emlxml}] -o OUTPUT [-os {parties,candidates}]
                       [-v]

Convert data from Dutch elections in EML XML files to a CSV file that has data
per party per stembureau.

optional arguments:
  -h, --help            show this help message and exit
  --add-contestname     Add contestname to output
  --add-percentages     Add percentages per party apart from absolute votes
  -i INPUT, --input INPUT
                        Input file or directory
  -if {emlxml}, --input-format {emlxml}
                        Input format
  -o OUTPUT, --output OUTPUT
                        Output CSV file (remember to add a CSV extension)
  -os {parties,candidates}, --output-structure {parties,candidates}
                        Structure of the output file, per party (default) or
                        per candidate. Note that this will eliminate some
                        columns to reduce file size.
  -v, --verbose         Display debug information

License

Licensed under the MIT license.

Credits

Written by Hay Kranen for Pointer.

About

Convert data from Dutch elections in EML XML files to a CSV file that has data per party per stemburea.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages