Skip to content

Instantly share code, notes, and snippets.

@plusreed
Last active September 18, 2022 17:51
Show Gist options
  • Save plusreed/b8ea893e7939a164a073ac0cf2057877 to your computer and use it in GitHub Desktop.
Save plusreed/b8ea893e7939a164a073ac0cf2057877 to your computer and use it in GitHub Desktop.
Spamton Sweepstakes Monitor
// Super rudimentary monitor for the spamton sweepstakes. Code is very ugly but works.
// Run with Node: `node pipis.js`
// You can change the interval by passing a seconds value: `node pipis.js 5`
// This will make it check every 5 seconds instead of every 10 seconds (default.)
const ENDPOINT = "https://spamton-prizes.fangamer.workers.dev/"
let last = null
async function main() {
// headers added to mask automated requests from pipis
const res = await fetch(ENDPOINT, {
method: 'GET',
headers: new Headers({
'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"
})
})
const json = await res.json()
const d = new Date()
console.log(`\n=== ${d} ===`)
if (last === null) {
console.log('STATUS: First run')
last = JSON.stringify(json)
} else if (last === JSON.stringify(json)) {
console.log('STATUS: No change since last run.')
} else {
console.log('STATUS: Change detected!')
console.log(' -> Donation diff:', Math.abs(parseInt(JSON.parse(last).donation_total) - json.donation_total))
console.log(' -> Goal changed?', JSON.parse(last).goal !== json.goal)
last = JSON.stringify(json)
}
console.log('Current donations amount:', json.donation_total)
console.log('Goal is:', json.donation_goal)
console.log('Prizes:\n', json.prizes.map(p => p.name.trim()).join('\n'))
console.log(`=== ${d} ===\n`)
}
(async () => {
let interval = process.argv[2] || 10
if (isNaN(parseInt(interval))) {
console.log('stop that')
interval = 10
}
console.log('Started at:', new Date())
console.log(`Polling every ${interval}s.`)
await main()
setInterval(main, parseInt(interval) * 1000)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment