Skip to main content

Simple python cli to extract voting results from PDfs published by the swiss parliament.

Project description

Vote Extractor

Simple python cli to extract voting results from PDFs published by the swiss parliament.

Installation

Dependencies

Make sure to have the following dependencies installed:

  • Python 3.10 or later
  • pip
  • pipx
  • Ghostscript (Windows)

Window Setup (Tested on Windows 11)

1. Install python & pip

  • Open the "Marketplace" and search for python. Install it. Alternatively, download and instal python here
  • Open a terminal: Start > Type "cmd" > start "Command Prompt"
  • Inside the terminal, type python --version and press "Enter". If you see something like this, python was succesfully installed:
\> python --version
Python 3.11.6
  • Also check if pip was installed by typing pip --version. If you see something like this you're good:
\> pip --version
pip 23.2.1 from C:\... (python 3..11)

2. Install pipx

Inside the terminal, first type

python -m pip install --user pipx

Confirm with enter and wait for the command to complete. Then type:

python -m pipx ensurepath

Again, confirm with enter and wait for completion. Open a new terminal (Start > Type "cmd" > start "Command Prompt") and type pipx --version to verify if the installation was succesful:

\> pipx --version
1.2.1

3. Install Ghostscript

Download and install Ghostscript from here.

Now you need to add two environment variables for Ghostscript to your PATH:

  • Press START
  • Type "Environment Variables" (Umgebungsvariablen?) and look for the option "Edit the system environment variables" (Umgebungsvariablen bearbeiten?)
  • A dialog opens. Double click "Path" in the top panel.
  • Add two new entries to the list, one for the bin and one for the lib directory of the just installed Ghostscript dependency. For the paths to the to folders looked like this (might be slightly different on your machine):
C:\Program Files\gs10.02.1\bin
C:\Program Files\gs10.02.1\lib
  • Confirm and close all dialogs.

Ghostscript should be setup correctly.

4. Install the App!

Now that all dependencies are installed, we can install the vote-extractor using pipx:

In a new terminal, type:

\> pipx install vote-extractor

Open a new terminal and type extract-votes --help. If you see the following output, everything is set up correctly:

\> extract-votes --help
usage: extract-votes [-h] [-x] [-c] [-n NAME] [-d DIRECTORY] pdf_url

positional arguments:
  pdf_url               Url to the pdf to extract votes from.

options:
  -h, --help            show this help message and exit
  -x, --excel           Store extracted votes as excel file.
  -c, --csv             Store extracted votes CSV file.
  -n NAME, --name NAME  Name of the generated file(s). Defaults to the input PDF name.
  -d DIRECTORY, --directory DIRECTORY
                        Name of the directory where the generated PDFs are stored. Defaults to `./out.`

Usage

To see an overview of what you can do, type:

extract-votes --help

To extract the votes from the following link:

https://www.parlament.ch/poly/AbstimmungSR/51/out/Abstimmung_51_6126.pdf

...and extract to both an excel file and a csv file named "my-test" inside the folder "my-output-folder", use the following command:

extract-votes --csv --excel --directory="my-output-folder" --name="my-test" https://www.parlament.ch/poly/AbstimmungSR/51/out/Abstimmung_51_6126.pdf

After that, you will see the following files:

my-output-folder
├── my-test.csv
└── my-test.xlsx

If you omit the --directory and --name arguments, the result would be different:

extract-votes --csv --excel  https://www.parlament.ch/poly/AbstimmungSR/51/out/Abstimmung_51_6126.pdf

The resulting files would be:

out
├── Abstimmung_51_6126.csv
└── Abstimmung_51_6126.xlsx

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vote_extractor-0.1.3.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

vote_extractor-0.1.3-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file vote_extractor-0.1.3.tar.gz.

File metadata

  • Download URL: vote_extractor-0.1.3.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for vote_extractor-0.1.3.tar.gz
Algorithm Hash digest
SHA256 97d44b8e20ff1ff3b8e68ce23be284cbfe185bbe25d32aaa4b9b6a71441c7ec0
MD5 6c1b1f302696d55f68c0b0d1ee1eafaa
BLAKE2b-256 1e451cf1cb7e0692601b82f9e68abde23beeafb693ee2a7c99e3185331235344

See more details on using hashes here.

File details

Details for the file vote_extractor-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for vote_extractor-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 349678992e8fa222fb591f1c5b0afe0d96e5539b26305fb375fc338dc3eb7032
MD5 97cf1c28142e5d9c1eb3c936a4e39c3f
BLAKE2b-256 2a152f539784d1edd89c56c53898d9b1899183409b3fcd9d1aaec2b7fd57413b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page