APFAKE
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
apfakedoes not call races.apfakevotes do not properly match actual election night spikes when ballots are counted.apfakeprecincts reporting and precincts reporting percentages are probably wrong.apfakedoes not work on zeros or initialization data. It needs the format&results=rufrom the AP API.
USAGE
Installing
apfake is easiest to install straight from PyPi. It requires a Python 3 environment.
pip install apfake
Using
apfake -f 2018-03-20-final.json -n 10 -d /tmp/foo/ -r 2018-03-20
apfake accepts four command-line options, two are required.
-f, --final-results-pathREQUIRED The path to the final results JSON file.-n, --numberREQUIRED The number of files to generate.-r, --racedateOPTIONAL TheYYYY-MM-DDracedate of the election. If the file specified infinal-results-pathhas a racedate in the filename, this will be used. Otherwise,apfakewill raise aValueError.-d, --data-directoryOPTIONAL A directory or set of directories to write the data to.apfakewill create these directories if they do not exist, and will also create a directory named for theracedateto hold the output files. Defaults to/tmp/.
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.
"""
results.keys()
dict_keys(['electionDate', 'timestamp', 'races', 'nextrequest'])
results['races'][0].keys()
dict_keys(['test', 'raceID', 'raceType', 'raceTypeID', 'officeID', 'officeName', 'party', 'seatName', 'reportingUnits'])
result['races][0]['reportingUnits'][0].keys()
dict_keys(['statePostal', 'stateName', 'level', 'lastUpdated', 'precinctsReporting', 'precinctsTotal', 'precinctsReportingPct', 'candidates'])
results['races'][0]['reportingUnits'][0]['candidates'][0].keys()
dict_keys(['first', 'last', 'party', 'incumbent', 'candidateID', 'polID', 'ballotOrder', 'polNum', 'voteCount'])
"""
Metadata
Release files for apfake 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| apfake-0.0.3.tar.gz | 4.1 kB | Without provenance | Details |
Release files / apfake-0.0.3.tar.gz
| Download URL | apfake-0.0.3.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5a20f9ec1396f8f2dba3b66291cf9aa7d95f25dd050b3f93bd0a848c5e2bb89f
|
|
BLAKE2b-256 checksum How to use checksums |
97519f0d9601b6fe60cdc3bfbba128c7f3dd1b77816c20cccdaedcd665e04ae3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for apfake 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.