Created
December 14, 2016 14:44
-
-
Save coston/031aeb9910aa3fd591f0399d80c9c5ee to your computer and use it in GitHub Desktop.
Web scraper with toolbar integration to display if AirPods are available. Built with Bitbar and Nightmare.js.
This file contains 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
#!/usr/bin/env /usr/local/bin/node | |
const bitbar = require('bitbar'); | |
const Nightmare = require('nightmare'); | |
const nightmare = Nightmare({ show: false }) | |
nightmare | |
.goto('http://www.apple.com/shop/product/MMEF2AM/A/airpods') | |
.wait('.as-purchaseinfo-dudeinfo-deliverymsg') | |
.evaluate(() => document.querySelector('.as-purchaseinfo-dudeinfo-deliverymsg').innerText) | |
.end() | |
.then(result => { | |
result === "Currently unavailable" ? console.log("🔮") : console.log("🎧") | |
console.log("---") | |
result === "Currently unavailable" ? console.log("AirPods Unavailable | color:purple href:http://www.apple.com/shop/product/MMEF2AM/A/airpods") : console.log("Buy AirPods! | color:green") | |
console.log('---') | |
console.log('Refresh | refresh=true') | |
}) | |
.catch(error => { | |
console.error('Search failed:', error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment