Skip to content

Instantly share code, notes, and snippets.

@zane
Created November 7, 2020 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zane/9de8e0853e92407fa5f0bde4d0beee2b to your computer and use it in GitHub Desktop.
Save zane/9de8e0853e92407fa5f0bde4d0beee2b to your computer and use it in GitHub Desktop.
#!/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