Skip to content

Instantly share code, notes, and snippets.

@tmbritton
Forked from chrislambe/check-dat-star-wars.js
Last active October 19, 2015 17:36
Show Gist options
  • Save tmbritton/455c9a4c0ec0f3b2b100 to your computer and use it in GitHub Desktop.
Save tmbritton/455c9a4c0ec0f3b2b100 to your computer and use it in GitHub Desktop.
Are tickets on sale yet for The Force Awakens?
var https = require('https'),
exec = require('child_process').exec;
// Check every 5 minutes
var checkDelay = 60000 * 5;
// Store the previous response body for comparison
var lastBody = null;
var checkTickets = function()
{
// 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);
return;
}
// NOPE, NO TICKETS YET
process.stdout.write("-- NOT YET.\n")
// Check again in checkDelay milliseconds
setTimeout(function() {
checkTickets();
}, checkDelay)
lastBody = body;
});
});
};
checkTickets();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment