Skip to main content

A CLI for pulling in election results from Clarity

Project description

https://img.shields.io/pypi/v/elex-clarity.svg https://img.shields.io/pypi/pyversions/elex-clarity.svg https://circleci.com/gh/washingtonpost/elex-clarity.svg?style=shield https://img.shields.io/pypi/l/elex-clarity.svg

A CLI tool for pulling in election results from sites using Clarity (the “election night reporting” product described here). This package is hosted on pypi.

Please use the Github issue tracker to submit bugs or request features.

Overview

This library

  • Provides a simple CLI tool for pulling in and formatting election results from a Clarity-backed website or local file

  • Separates data retrieval from data formatting

  • By default, returns results formatted like so

    {
        "2020-11-03_GA_G_P": {
            "id": "2020-11-03_GA_G_P",
            "source": "clarity",
            "precinctsReportingPct": 100.0,
            "counts": {
                "donald_j_trump_i_rep": 2461837,
                "joseph_r_biden_dem": 2474507,
                "jo_jorgensen_lib": 62138
            },
            "office": "P",
            "lastUpdated": "2020-11-20T20:37:06Z",
            "subunits": {
                "appling": {
                    "id": "appling",
                    "counts": {
                        "donald_j_trump_i_rep": 6526,
                        "joseph_r_biden_dem": 1779,
                        "jo_jorgensen_lib": 36
                    }
                },
                ...
            }
        }
    }

Installation

  • Make sure you have python 3.7+ installed

  • Optional: we recommend that you set up a virtualenv and activate it

  • pip install elex-clarity

Usage

All CLI commands require a Clarity election ID and state postal code. For example

elexclarity 105369 GA

The election ID can be found by navigating to the election in question in whichever results site you’re viewing. For example, for Georgia, the Secretary of State’s website links to election results. Following the Current Election Results link you get to a clarity page with many election results pages. Looking at the 2020-current results will lead to https://results.enr.clarityelections.com/GA/105369/web.264614/#/summary, which contains the election ID right after the state postal code.

Other parameters

Title

Name

Description

Type

Required?

Default

style

what broad type of formatting should be done?

one of [default, raw]

N

default

outputType

what specific type of formatting should be done?

one of [results, settings, summary]

N

results

level

what level of data should be fetched/returned?

one of [precinct, county, state]

N

county

countyName

Name of county to get results from if counties have their own pages

string

N

officeID

what office ID(s) should be returned?

a comma separated list of office IDs

N

countyMapping

an object with race names (as provided via Clarity) mapped to some other identifier that should be used in results formatting. Sample formats can be found in the tests/fixtures folder

object

N

voteCompletionMode

the method that should be used to determine whether a precinct is fully reporting

string

N

percentReporting

precinctsReportingPct

a county-level override for the precincts reprting percent that applies to all subunits, given as a mapping between county IDs and percents (does not change the value of the reportingStatus field)

object

N

filename

the path to read results from (if you don’t want to ping a Clarity site)

string

N

Example invocations

Retrieving raw data:

  • elexclarity 105369 GA --outputType=summary --style=raw

  • elexclarity 105369 GA --outputType=settings --style=raw

  • elexclarity 105369 GA --level=precinct --style=raw

  • elexclarity 106043 CA --countyName Santa_Clara --level=precinct

Retrieving + formatting settings (for presidential races):

  • elexclarity 105369 GA --outputType=settings --officeID=P

Retrieving + formatting results:

  • elexclarity 105369 GA --level=precinct --countyMapping='{"Worth": "13321"}'

  • elexclarity 105369 GA --level=precinct

  • elexclarity 105369 GA --level=precinct --voteCompletionMode=voteTypes

  • elexclarity 105369 GA --level=county

  • elexclarity 106210 WV --level=county --countyMapping='<mapping json>'

  • elexclarity 105369 WV --level=state

Formatting data from a local file:

  • elexclarity 105369 GA --level=precinct --filename="tests/fixtures/results/ga_atkinson_precincts_11-3.xml" --countyMapping='<mapping json>'

  • elexclarity 105369 GA --level=county --filename="tests/fixtures/ga_counties_11-3.xml" --countyMapping='<mapping json>'

Development

  • Clone this repository

  • pip install -r requirements.txt

  • tox

  • You should see some code coverage info and test results

  • If the above was successful, you are ready for development

Releasing a New Version

In preparation for a new release:

  • Decide what the next version will be per semantic versioning

  • Make a new branch named release/<version number>

  • Update the changelog with all changes that will be included in the release

  • Commit your changes and make a PR against main

  • Once the changes are merged, tag main (or develop for a beta release) with the release’s version number and push that tag (git push --tags)

  • Merge main into develop

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

elex-clarity-0.0.9.tar.gz (13.8 kB view details)

Uploaded Source

Built Distributions

elex_clarity-0.0.9-py3.7.egg (31.4 kB view details)

Uploaded Source

elex_clarity-0.0.9-py2.py3-none-any.whl (16.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file elex-clarity-0.0.9.tar.gz.

File metadata

  • Download URL: elex-clarity-0.0.9.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.12

File hashes

Hashes for elex-clarity-0.0.9.tar.gz
Algorithm Hash digest
SHA256 8e6fd4efda3c1b6977600de1696e7219444735108bb7880152a6a982e4c7b390
MD5 15abef07c66e9cec6bb52cd251686a32
BLAKE2b-256 15831efb6e67d079e0c147f8b5893ea9f9cdbd11fdeffe8972c28066415a4918

See more details on using hashes here.

File details

Details for the file elex_clarity-0.0.9-py3.7.egg.

File metadata

  • Download URL: elex_clarity-0.0.9-py3.7.egg
  • Upload date:
  • Size: 31.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.12

File hashes

Hashes for elex_clarity-0.0.9-py3.7.egg
Algorithm Hash digest
SHA256 8aa4ef57892874df38729d21011d4cbc18038ead12f6ba014831a5bed84922ad
MD5 9e8188ddcc6d837694c1f8e6684fda49
BLAKE2b-256 79e43f100dac478061e1c213ec91a77be324afeac86ba136449d299efbeebf71

See more details on using hashes here.

File details

Details for the file elex_clarity-0.0.9-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for elex_clarity-0.0.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 501760e8014cfe19d77135c241aebcfe41ffea0505fb40d40f3279551765b392
MD5 efc481e8323a81b5b6ed3ef35ae6507d
BLAKE2b-256 66264e599072788b1a5cf45b66da46011fd651db40e8229f09cc05b03a763625

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