This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Python client for parsing the Associated Press's elections API.

Project Description

Requirements

  • Python 2.7
  • pip

Optional requirements:

  • PostgreSQL
  • MongoDB

Installation

Install the Python library:

pip install nyt-ap-elections

Set your AP API key:

export AP_API_KEY=<MY_AP_API_KEY>

Usage

Command line utility

This tool is primarily designed for use on the command line using standard *NIX operations like pipes and output redirection.

To write a stream of races in CSV format to your terminal, run:

elex init-races '11-03-2015'

To write this data to a file:

elex init-races '11-03-2015' > races.csv

To pipe it into PostgreSQL:

elex init-races '11-03-2015' | psql elections -c "COPY races FROM stdin DELIMITER ',' CSV HEADER;"```

Output could also be piped to tools like sed, awk, or csvkit.

Demo app

See the NPR Visuals Demo Loader.

Modules

Use the election loader manually from within your project.

from elex.parser import api
from elex import loader
from elex.loader import postgres

e = api.Election(electiondate='2015-11-03', testresults=False, liveresults=True, is_test=False)
raw_races = e.get_races(omitResults=False, level="ru", test=False)

races, reporting_units, candidate_reporting_units = e.get_units(raw_races)
candidates, ballot_positions = e.get_uniques(candidate_reporting_units)

# Now you can do whatever it is you want with these objects.

Options

Recording

Flat files

Will record timestamped and namespaced files to the ELEX_RECORDING_DIR before parsing.

export ELEX_RECORDING=flat
export ELEX_RECORDING_DIR=/tmp

MongoDB

Will record a timestamped record to MongoDB, connecting via ELEX_RECORDING_MONGO_URL and writing to the ELEX_RECORDING_MONGO_DB database.

export ELEX_RECORDING=mongodb
export ELEX_RECORDING_MONGO_URL=mongodb://localhost:27017/  # Or your own connection string.
export ELEX_RECORDING_MONGO_DB=ap_elections_loader

Development

Run tests

nosetests
Release History

Release History

This version
History Node

0.0.41

History Node

0.0.40

History Node

0.0.39

History Node

0.0.38

History Node

0.0.37

History Node

0.0.36

History Node

0.0.35

History Node

0.0.34

History Node

0.0.33

History Node

0.0.32

History Node

0.0.31

History Node

0.0.30

History Node

0.0.29

History Node

0.0.28

History Node

0.0.27

History Node

0.0.25

History Node

0.0.24

History Node

0.0.23

History Node

0.0.22

History Node

0.0.21

History Node

0.0.20

History Node

0.0.19

History Node

0.0.18

History Node

0.0.17

History Node

0.0.16

History Node

0.0.15

History Node

0.0.14

History Node

0.0.13

History Node

0.0.12

History Node

0.0.11

History Node

0.0.10

History Node

0.0.9

History Node

0.0.8

History Node

0.0.7

History Node

0.0.6

History Node

0.0.5

History Node

0.0.4

History Node

0.0.3

History Node

0.0.2

History Node

0.0.1

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
nyt-ap-elections-0.0.41.tar.gz (16.8 kB) Copy SHA256 Checksum SHA256 Source Nov 20, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting