Skip to content

Instantly share code, notes, and snippets.

@Aupajo
Last active November 5, 2020 22:10
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 Aupajo/9d4dba6d0029cfa95132b9eaf29c100e to your computer and use it in GitHub Desktop.
Save Aupajo/9d4dba6d0029cfa95132b9eaf29c100e to your computer and use it in GitHub Desktop.
Georgia Bitbar
#!/usr/bin/env node
const fetch = require('node-fetch')
function formattedCount(number) {
return number.toLocaleString()
}
async function start() {
const url = 'https://www.huffpost.com/elections/president.json'
const response = await fetch(url)
const data = await response.json()
const races = data.races
const georgia = races.find(race => race.name === 'Georgia')
const completionPercentage = georgia.eevp
const candidates = georgia.candidates
const trumpVotes = candidates.find(candidate => candidate.name === 'Trump').n
const joeVotes = candidates.find(candidate => candidate.name === 'Biden').n
let votesTowardsJoe = joeVotes - trumpVotes
let colour = 'red'
if (votesTowardsJoe > 0) {
colour = 'blue'
}
console.log(`GA ${completionPercentage}% ${formattedCount(votesTowardsJoe)} | color=${colour}`)
console.log('---')
console.log('Results for Georgia')
console.log(`Biden: ${formattedCount(joeVotes)}`)
console.log(`Trump: ${formattedCount(trumpVotes)}`)
console.log('View votes | href=https://www.nytimes.com/interactive/2020/11/03/us/elections/results-georgia.html')
}
start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment