newsdev/apfake

Name: apfake

Owner: NYT Newsroom Developers

Description: A command-line tool for generating AP API JSON files for testing elections applications.

Created: 2018-03-19 14:22:01.0

Updated: 2018-05-22 22:22:25.0

Pushed: 2018-05-11 19:19:54.0

Homepage: null

Size: 9

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

APFAKE

screen shot 2018-03-19 at 10 21 06 am

Have you ever thought “I should record the AP API test that's coming in a half hour” only to find out that it actually concluded a half hour AGO? I've done this several times. And if I've done it before, I have to assume others have done it as well.

Taking the FINAL JSON state file of an AP API election test (e.g., what happens if you hit the test URL after a test has run but before it's zeroed out in the moments before a new test or a live election), apfake will generate a file of zeros and then n intermediate states between the zeros and the final file with a smoothly incrementing set of votes.

In short: If you give it the last file of a test, apfake will generate all the missing files for you.

CAVEATS
USAGE
Installing

apfake is easiest to install straight from PyPi.

install apfake
Using
ke -f 2018-03-20-final.json -n 10 -d /tmp/foo/ -r 2018-03-20

apfake accepts four command-line options, two are required.

DEBUGGING WITCHERY

This is the shape that apfake expects your JSON to have. If you use the format &results=ru it will probably work. If you use a different format, it might work, though YMMV.


lts.keys()
_keys(['electionDate', 'timestamp', 'races', 'nextrequest'])

lts['races'][0].keys()
_keys(['test', 'raceID', 'raceType', 'raceTypeID', 'officeID', 'officeName', 'party', 'seatName', 'reportingUnits'])

lt['races][0]['reportingUnits'][0].keys()
_keys(['statePostal', 'stateName', 'level', 'lastUpdated', 'precinctsReporting', 'precinctsTotal', 'precinctsReportingPct', 'candidates'])

lts['races'][0]['reportingUnits'][0]['candidates'][0].keys()
_keys(['first', 'last', 'party', 'incumbent', 'candidateID', 'polID', 'ballotOrder', 'polNum', 'voteCount'])


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.