Advertisement
JoshuaB

how-many-tickets-left.js

Mar 21st, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // how to run it:
  2. //   $ npm install cheerio
  3. //   $ npm install request
  4. //   $ npm install colors
  5. //   $ node how-many-tickets-left.js
  6.  
  7. var cheerio = require('cheerio');
  8. var request = require('request');
  9. var colors = require('colors');
  10.  
  11. var URL = 'https://www.eventbrite.com/tickets-external?eid=10494321799&ref=etckt';
  12. var PATH = '#remaining_quant_23333901_None';
  13.  
  14. request(URL, function (error, response, body) {
  15.   if (error || response.statusCode !== 200) {
  16.     throw new Error("Your intenet is jacked up. Try again when its sane again.");
  17.   }
  18.  
  19.   var $ = cheerio.load(body);
  20.   run($);
  21. });
  22.  
  23. function run($) {
  24.   var text = $(PATH).text();
  25.   var match = /\d+/.exec(text);
  26.  
  27.   if (match === null) {
  28.     throw new Error("The webpage is not displaying correctly. Check again.");
  29.   }
  30.  
  31.   var tickets = match[0];
  32.   if (tickets === 0) {
  33.     console.log("Fuck. ".red + "They're out of tickets.");
  34.     return;
  35.   }
  36.  
  37.   if (tickets > 0) {
  38.     console.log('Hell ya. '.rainbow + "They still have " + tickets + " tickets left.");
  39.     return;
  40.   }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement