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.2.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: vote_extractor-0.1.2.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.0 CPython/3.10.12 Linux/5.15.0-88-generic

File hashes

Hashes for vote_extractor-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6a4d4c639a12dcb5b55082649d96830b51bdea067bad43101cf1936bbfaeb54d
MD5 c4885687d8d3ed047d765e2d06a8e0e4
BLAKE2b-256 5206771fa08c6836d60971c94866a207c244d4ef084776f533616179b2b24ec9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: vote_extractor-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.0 CPython/3.10.12 Linux/5.15.0-88-generic

File hashes

Hashes for vote_extractor-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 582e8c0d4f0e430a6d0f9e1fa007cf6420cb28becbfeb97f0bdb823ecc9aa886
MD5 ffd07eee4922bc2393157788a9511fde
BLAKE2b-256 c3643b829dde0ecb0b092393507e46fce3c7047c87027452b1a8713adf6c06e3

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