Last active
November 6, 2020 14:35
-
-
Save keelerm84/ba16f05ad0b6badbd0b5d530d40c395d to your computer and use it in GitHub Desktop.
Short function to monitor voting results in battleground states
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
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 | |
}' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output of the above function.