Skip to content

Instantly share code, notes, and snippets.

@JavadocMD
Created Aug 3, 2020
Embed
What would you like to do?
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