Last active
May 28, 2016 02:10
-
-
Save bradoyler/72fab9272fe95ed5f0b049306eac6dad to your computer and use it in GitHub Desktop.
Get state & county level Presidential Election results from AP (via Elex)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### uses Elex, Jq & S3 to persist state & county level Presidential Election results (AP) to s3 | |
# S3 url: MUST be set to your bucket and path. | |
S3_URL='http://s3.amazonaws.com/bucket-name/folder-name/$1_results.json' | |
# Get results and upload to S3 | |
elex results $1 -o json \ | |
| jq -c '[ | |
.[] | | |
select(.officename == "President") | | |
{ | |
id: .id, | |
raceid: .raceid, | |
officename: .officename, | |
officeid: .officeid, | |
racetype: .racetype, | |
racetypeid: .racetypeid, ## D,E,R,S | |
fipscode: .fipscode, | |
reportingunitname: .reportingunitname, ## ie. county name | |
precinctsreporting: .precinctsreporting, | |
precinctstotal: .precinctstotal, | |
statepostal: .statepostal, | |
candidateid: .candidateid, | |
first: .first, | |
last: .last, | |
party: .party, | |
votecount: .votecount, | |
votepct: .votepct, | |
winner: .winner, | |
level: .level, | |
test: .test, | |
lastupdated: .lastupdated | |
} | |
]' \ | |
| gzip -vc \ | |
| aws s3 cp - s3://$S3_URL \ | |
--acl public-read \ | |
--content-type=application/json \ | |
--content-encoding gzip | |
# Check response headers | |
curl -I $S3_URL | |
# Get first entry of uploaded json | |
curl -s --compressed $S3_URL | jq '[.[]][0]' |
Author
bradoyler
commented
May 28, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment