newsdev/elex-loader

Name: elex-loader

Owner: NYT Newsroom Developers

Description: The NYT AP election loader scripts

Created: 2015-11-20 14:48:10.0

Updated: 2018-05-23 02:38:42.0

Pushed: 2017-11-07 21:46:27.0

Homepage: null

Size: 251

Language: Shell

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

AP ELECTION LOADER

Relies on Elex, a command-line tool to get results from the AP Election API 2.0. Demonstrates a method putting those results into a Postgres database using the COPY method and the loader's CSV output.

Assumptions

The following things are assumed to be true in this documentation.

See “Chapter 2: Install Virtualenv” of NPR's development environment blog post for details.

Having trouble on OS X El Capitan? See: Can't install virtualenvwrapper on OSX 10.11 El Capitan.

Getting started
rtualenv elex-loader
clone git@github.com:newsdev/elex-loader.git && cd elex-loader
install -r requirements.txt
ripts/$ENV/bootstrap.sh

The bootstrap.sh script will create databases and the user necessary for local development. Note: This does not exist for non-development environments. Please use commands in elex-dotfiles instead.

Environments

The New York Times defines a handful of different environments; principally, dev, stg and prd.

Use cases
Load initial data
ripts/$ENV/reload.sh

The AP will make “live zeros” available in the morning of an election day. You can run reload.sh to get an entire new set of data, including races, reporting units, candidates and zeroed-out results.

Load results on election night
ripts/$ENV/daemon.sh

The daemon will run 100,000 times (seriously) unless it is stopped. We control ours with a custom Supervisord instance and a modified /etc/supervisord.conf. This configuration file is available in elex-dotfiles along with other secrets.

Set a wait interval

You might want to control how long the daemon waits between cycles. This is hardcoded to a default – 15s in production, 30s elsewhere. You can create the file /tmp/elex_loader_timeout.sh and export an ELEX_LOADER_TIMEOUT variable like this:

rt ELEX_LOADER_TIMEOUT=60

The daemon checks for this file and sources it if it exists in every loop, which means you can dynamically control the wait time. For example, we do this in our admin.

Load results once
ripts/$ENV/update.sh

Sometimes you just need to load a single update, e.g., to grab final results after we've turned off the loader. This command will get new results without baking or reloading any other parts of the database.

Load delegate data
ripts/$ENV/delegates.sh

Often, the AP will update delegate information after our daemon has stopped running. To update just delegates for a given racedate, run this command.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.