Skip to content

Instantly share code, notes, and snippets.

@chrislambe
Last active April 11, 2017 12:28
Show Gist options
  • Save chrislambe/05240e1547f246f2444d to your computer and use it in GitHub Desktop.
Save chrislambe/05240e1547f246f2444d to your computer and use it in GitHub Desktop.
Are tickets on sale yet for The Force Awakens?
var https = require('https'),
http = require('http'),
exec = require('child_process').exec,
fs = require('fs');
// Check every 5 minutes
var checkDelay = 60000 * 5;
// Store the previous response body for comparison
var lastBody = null;
var themeDownloaded = false;
var themeFilePath = './swtheme.wav';
var themeUrl = 'http://www.kiwi-nutz.com/sounds/wav_starwars/swtheme.wav';
if(fs.existsSync(themeFilePath))
{
themeDownloaded = true;
}
else
{
var themeFile = fs.createWriteStream(themeFilePath);
http.get(themeUrl, function(response) {
response.pipe(themeFile);
themeFile.on('finish', function() {
themeFile.close(function() {
themeDownloaded = true;
});
});
});
}
var checkTickets = function(showBody)
{
// Start check...
process.stdout.write('May the force');
https.get({
protocol: 'https:',
host: 'drafthouse.com',
path: '/ajax/.showtimes-show-starwars/0000/A000010000%7CA000009999',
headers: {
'cache-control': 'max-age=0'
}
}, function(response) {
// console.log(response.body);
response.on('data', function(chunk) {
var body = chunk.toString(),
url = 'https://drafthouse.com/starwars/austin';
if(body !== lastBody && lastBody !== null)
{
// OMG THEY'RE READY, GOGOGOGO
process.stdout.write(' be with you!');
console.log(url);
exec("open " + url);
if(themeDownloaded) exec('afplay ./swtheme.wav');
return;
}
// NOPE, NO TICKETS YET
process.stdout.write("-- NOT YET.\n")
if(showBody === true) console.log(body);
// Check again in checkDelay milliseconds
setTimeout(function() {
checkTickets();
}, checkDelay)
lastBody = body;
});
});
};
checkTickets(true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment