Core repo for election results data acquisition, transformation and output.
OpenElections core is developed and tested using Python 3. The package might not work with older Python distributions.
You'll:
You should use pipenv to work on Open Elections inside a virtualized development environment.
The easiest way is to install these tools system-wide with pip
(you may need to use sudo
):
bash
$ pip install --upgrade pipenv
Then, to make a virtual environment for open elections work:
bash
$ pipenv install --dev
To activate the virtual environment, run:
bash
$ pipenv shell
Fork this repo by hitting the "Fork" button above, and clone your fork to your computer:
bash
$ git clone https://github.com/[my_github_user]/openelections-core.git
$ cd openelections-core
Turn setup and activate the virtual environment from the previous step, if you haven't already:
bash
$ pipenv install --dev
$ pipenv shell
Install MongoDB
To store your data in MongoDB, you need only install Mongo. The default configuration should auto-create the databases and tables you need, as you need them.
At the very least, you'll want to make sure the values in the MONGO
variable work for the way you've installed and configured MongoDB on your system.
Create a settings.py
file.
bash
$ cp settings.py.tmplt settings.py
You can put this settings file anywhere on your filesystem. You'll need to set the OPENELEX_SETTINGS
environment variable to the absolute path to the settings.py
file that you created.
You can set the OPENELEX_SETTINGS
environment variable by creating a .env
file in your repository. For example:
OPENELEX_SETTINGS=/Users/[myusername]/Development/openelections-core/settings.py
Running pipenv shell
will automatically source any variable in your .env
file.
Test it out by running openelex --help
, you should see something like:
```bash $ openelex --help Usage: openelex [OPTIONS] COMMAND [ARGS]...
Options: --help Show this message and exit.
Commands: bake.election_file Write election and candidate data with on... bake.results_status_json Output a JSON file describing available... bake.state_file Write election and candidate data along with... cache.clear Delete files in state cache diretory cache.files List files in state cache diretory datasource.elections List elections for a state. datasource.filename_url_pairs List mapping of standard filenames to source... datasource.mappings List metadata mappings for a state datasource.target_urls List source data urls for a state fetch Scrape data files and store in local file... load.run Load cached data files into the database load_metadata.run Populate metadata in database from fixture... publish Publish baked result files shell Open a Python shell, bootstrapping the... transform.list Show available data transformations transform.reverse Reverse a previously run transformation transform.run Run data transformations validate.list Show available validations for state validate.run Run data validations for state ```
Running commands looks something like this:
bash
$ openelex cache.clear --state=NY
0 files deleted
0 files still in cache
You can also get help on particular commands, e.g. openelex --help cache.clear
.
If you are going to load results, you need to configure MongoDB connections in
openelex/settings.py
.
If you are a core contributor who needs to publish baked results to one of the GitHub repositories, you will need to define further settings.
To set GitHub credentials, you must first create a personal access token and then uncomment and set these values in openelex/settings.py
:
python
GITHUB_USERNAME = ''
GITHUB_ACCESS_TOKEN = ''
You only need to do this if you plan to write data loaders or transforms.
bash
$ cd openelex
$ openelex load_metadata.run --collection=office
$ openelex load_metadata.run --collection=party
Bumps ipython from 0.13.2 to 7.16.3.
Sourced from ipython's releases.
7.9.0
No release notes provided.
7.8.0
No release notes provided.
7.7.0
No release notes provided.
7.6.1
No release notes provided.
7.6.0
No release notes provided.
7.5.0
No release notes provided.
7.4.0
No release notes provided.
7.3.0
No release notes provided.
7.2.0
No release notes provided.
7.1.1
No release notes provided.
7.1.0
No release notes provided.
7.0.1
No release notes provided.
7.0.0
No release notes provided.
7.0.0-doc
No release notes provided.
7.0.0rc1
No release notes provided.
7.0.0b1
No release notes provided.
6.2.1
No release notes provided.
... (truncated)
d43c7c7
release 7.16.35fa1e40
Merge pull request from GHSA-pq7m-3gw7-gq5x8df8971
back to dev9f477b7
release 7.16.2138f266
bring back release helper from master branch5aa3634
Merge pull request #13341 from meeseeksmachine/auto-backport-of-pr-13335-on-7...bcae8e0
Backport PR #13335: What's new 7.16.28fcdcd3
Pin Jedi to <0.17.2.2486838
release 7.16.120bdc6f
fix conda buildDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
The National Institute of Standards and Technology has developed a common data format for election results. The more people (and election agencies) use this format, the easier it will be for all of us to share data.
Software to ease conversion to the common data format is here.
Several million Americans live and vote in the five US territories. They deserve to be included in your election results, even if they have only non-voting representation in Congress.
For the history of the exclusion of these people -- most of whom are not white -- from power in the United States, see How to Hide an Empire by Immerwahr.
Last time I checked, some of your datasets were works in progress, rather than complete. It would be great to have a resource that a visitor to the repo could find, detailing exactly what is available completely -- for each state, district, territory, and for each election:
Bumps urllib3 from 1.25.7 to 1.25.8.
2a57bc5
Release 1.25.8 (#1788)a2697e7
Optimize _encode_invalid_chars (#1787)d2a5a59
Move IPv6 test skips in server fixturesd44f0e5
Factorize test certificates serialization84abc7f
Generate IPV6 certificates using trustme6a15b18
Run IPv6 Tornado server from fixture4903840
Use trustme to generate IP_SAN cert9971e27
Empty responses should have no lines.62ef68e
Use trustme to generate NO_SAN certsfd2666e
Use fixture to configure NO_SAN test certsDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
The following pattern is used often to read csv files:
with open(filename, 'rU') as csvfile:
reader = unicodecsv.DictReader(csvfile)
I think this worked in python2 since the str
and bytes
types were synonymous. However, this breaks in python3 since unicodecsv
expects the file to be opened in binary mode, which it is not.
For example, the following fails in python3 with the error AttributeError: 'str' object has no attribute 'decode'
```
import unicodecsv
filename = 'openelex/us/md/mappings/md.csv'
with open(filename, "r") as data:
reader = unicodecsv.DictReader(data)
for row in reader:
print(row)
Using `csv` instead of `unicodecsv` fixes the issue.
import csv
filename = 'openelex/us/md/mappings/md.csv' with open(filename, "r") as data: reader = csv.DictReader(data) for row in reader: print(row) ```
Is there something wrong with my setup, or is this broken for other people as well?
The goal of OpenElections is to create the first free, comprehensive, standardized, linked set of election results data for the United States.
GitHub Repositoryopenelections elections