Skip to content

Instantly share code, notes, and snippets.

@keelerm84
Last active November 6, 2020 14:35
Show Gist options
  • Save keelerm84/ba16f05ad0b6badbd0b5d530d40c395d to your computer and use it in GitHub Desktop.
Save keelerm84/ba16f05ad0b6badbd0b5d530d40c395d to your computer and use it in GitHub Desktop.
Short function to monitor voting results in battleground states
function vote {
curl --silent https://alex.github.io/nyt-2020-election-scraper/battleground-state-changes.csv | \
awk -v red="$(tput setaf 1)" \
-v blue="$(tput setaf 4)" \
-v reset="$(tput sgr0)" \
-F "," '
NR==1 { next }
matches[$1] == 1 { next }
{
matches[$1]=1
state=$1
leader=$3
margin=$7
remaining=$8
percentage=margin/remaining*100
color = leader == "Biden" ? blue : red
printf "%s %s%s%s +%d (%.2f%% of remaining)\n", state, color, leader, reset, margin, percentage
}'
}
@keelerm84
Copy link
Author

Example output of the above function.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment