Skip to content

Instantly share code, notes, and snippets.

@demipixel
Created June 27, 2016 03:39
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 demipixel/1a5a42022c24d88de1308a934bd78246 to your computer and use it in GitHub Desktop.
Save demipixel/1a5a42022c24d88de1308a934bd78246 to your computer and use it in GitHub Desktop.
Wake me up when it's out!
/*
HOW TO RUN:
- Download and Install node.js. Check by running: node -v
- Create a folder "wakeup" and stick this index.js inside
- cd to the folder. On a mac, this might look like: cd Desktop/wakeup
no idea on a windows, I think it's something like: cd C:\Users\username\Desktop\wakeup
- Run: npm install request
- Run: npm install sfx
- Run: node index (to stop it, use cntrl-C or cntrl-D depending on your system.)
- Should have an alarm go off when the new update is out!
DON'T FORGET TO SET THE SOUND_FILE BELOW
Options: If you want to be waken up in case there are errors in the program, use "WAKE_UP_AFTER_ERRORS"
Set this to the number of errors in a row before being woken up. I recommend 10, but by default it's off at 0.
*/
var WAKE_UP_AFTER_ERRORS = 0;
var SOUND_FILE = 'BuzExplode.m4a'; // Must be in the same "wakeup" folder
var LAST_GID = '250329347071682810'; // Current blog ID before 0.13, change if you want to use in the future
var request = require('request');
var sfx = require('sfx');
var currentCheck = 0; // Current check time
var errors = 0;
function check() {
if (currentCheck && Date.now() - currentCheck < 60*1000) return; // Check if in the middle and not timed out
currentCheck = Date.now(); // Set current check
if (WAKE_UP_AFTER_ERRORS > 0 && errors >= WAKE_UP_AFTER_ERRORS) {
playAlarm();
currentCheck = 0;
return;
}
request('http://api.steampowered.com/ISteamNews/GetNewsForApp/v0002/?appid=427520&count=3&maxlength=300&format=json', function(err, http, body) {
currentCheck = 0; // Reset, we can check again!
if (err) errors++;
try {
articles = JSON.parse(body).appnews.newsitems;
if (articles[0].gid != LAST_GID) playAlarm();
errors = 0;
console.log('Checked');
} catch (e) {
console.log(e);
errors++;
}
});
}
function playAlarm() {
console.log('Alarm '+(process.argv[2] == 'test' ? 'TEST' : ''));
sfx.play(SOUND_FILE, 100);
}
if (process.argv[2] == 'test') {
playAlarm();
} else {
check(); // Call check and put it on a 10 second interval
setInterval(check, 10*1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment