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
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
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.
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.
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.
The New York Times defines a handful of different environments; principally, dev
, stg
and prd
.
dev
: Hits test URLs by default. Assumes a local Postgres database where the local user is a superuser.stg
: Hits test URLs by default. Requires a Postgres user / host / password to be defined in the environment. We use a .pgpass
file and export the rest in /etc/environment
. Check out elex-dotfiles for more.prd
: Hits live URLs by default. Requires a Postgres user / host / password to be defined in the environment.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.
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.
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.
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.
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.