Created
November 7, 2020 02:46
-
-
Save zane/9de8e0853e92407fa5f0bde4d0beee2b to your computer and use it in GitHub Desktop.
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
#!/usr/local/bin/bb | |
(require '[babashka.curl :as curl]) | |
(require '[cheshire.core :as json]) | |
(def url "https://static01.nyt.com/elections-assets/2020/data/api/2020-11-03/votes-remaining-page/national/president.json") | |
(def pa-index 38) | |
(let [{:keys [body]} | |
(curl/get url) | |
all-candidates | |
(get-in (json/parse-string body true) | |
[:data :races pa-index :candidates]) | |
{[biden] "Biden" [trump] "Trump"} | |
(group-by :last_name all-candidates) | |
total (transduce (map :votes) + all-candidates)] | |
(->> (/ (- (:votes biden) | |
(:votes trump)) | |
total) | |
(* 100) | |
(float) | |
(printf "%.2f%%"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment