Skip to content

Instantly share code, notes, and snippets.

@coston
Created December 14, 2016 14:44
Show Gist options
  • Save coston/031aeb9910aa3fd591f0399d80c9c5ee to your computer and use it in GitHub Desktop.
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.
#!/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