Created
February 22, 2016 19:56
-
-
Save MattSandy/d865a221e5930ca77b8c to your computer and use it in GitHub Desktop.
Food Tracker Notification for Pizza Luce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'); | |
var cheerio = require('cheerio'); | |
var notifier = require('node-notifier'); | |
var status = ""; | |
var url = "[tracking url]"; | |
var interval = setInterval(function(url, notifier) { | |
get_status(url, notifier); | |
}, 30000, url, notifier); | |
function get_status(url) { | |
try { | |
request({method: 'GET', uri: url}, function (error, response, body) { | |
if (!error) { | |
var $ = cheerio.load(body); | |
if(status != $("#order-tracker-status-text").text().trim()) { | |
status = $("#order-tracker-status-text").text().trim(); | |
notifier.notify({ | |
'title': 'Pizza Status', | |
'message': status | |
}); | |
} | |
if(status) { | |
console.log(status); | |
} | |
} else { | |
console.log("We’ve encountered an error: " + error); | |
} | |
}); | |
} catch (err) { | |
console.log(err); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment