Skip to content

Instantly share code, notes, and snippets.

@JavadocMD
Created August 3, 2020 22:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JavadocMD/49309d286ba24dc3eb2d25236263afd8 to your computer and use it in GitHub Desktop.
Save JavadocMD/49309d286ba24dc3eb2d25236263afd8 to your computer and use it in GitHub Desktop.
Follow a Blaseball game for the given team and print updates to the console.
import { default as Socket } from 'socket.io-client'
// dependencies: socket.io-client
// Usage example:
// $ node ./dist/index.js "Philly Pies" | espeak-ng -v en-us -s 120
function main() {
const team = process.argv[2] || 'Philly Pies'
const socket = Socket('https://blaseball.com')
socket.on('connect', () => {
console.log('> connected')
})
let prevUpdate = ''
socket.on('gameDataUpdate', data => {
const game = data.schedule.find(x => x.awayTeamName === team || x.homeTeamName === team)
let currUpdate = prevUpdate
if (game) {
currUpdate = game.lastUpdate || '(No update.)'
} else {
currUpdate = `No game in progress for team "${team}"`
}
if (currUpdate !== prevUpdate) {
console.log(currUpdate)
prevUpdate = currUpdate
}
})
socket.on('disconnect', reason => {
console.log(`> disconnected (${reason})`)
})
process.on('SIGINT', () => {
socket.close()
process.exit()
})
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment