-
-
Save flesch/b1c0c984ef7dc1d6a292c2609d8f1818 to your computer and use it in GitHub Desktop.
Old Navy: undefined • undefined
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
{ | |
"url": "https://oldnavy.gap.com/browse/product.do?pid=550822002", | |
"date": "2021-06-29T20:44:09.008Z" | |
} |
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
const { JSDOM } = require('jsdom'); | |
const Gists = require('gists'); | |
const IFTTT = require('node-ifttt-maker'); | |
const gists = new Gists({ token: process.env.GITHUB_GIST_ACCESS_TOKEN }); | |
const ifttt = new IFTTT(process.env.IFTTT_MAKER_KEY); | |
(async () => { | |
try { | |
const url = 'https://oldnavy.gap.com/browse/product.do?pid=139537002'; | |
const { window } = await JSDOM.fromURL(url); | |
const [name, currentPrice] = Array.from(window.document.querySelectorAll('h1.product-title, h5.product-price')).map((node) => { | |
return node.textContent.trim(); | |
}); | |
const { body } = await gists.get('b1c0c984ef7dc1d6a292c2609d8f1818'); | |
const { price: previousPrice } = JSON.parse(body.files['db.json'].content); | |
if (currentPrice !== previousPrice) { | |
const iftttResponse = await ifttt.request({ | |
event: 'old_navy_price_change', | |
params: { | |
value1: name, | |
value2: currentPrice, | |
value3: previousPrice, | |
}, | |
}); | |
} | |
console.log({ name, currentPrice, previousPrice }); | |
const db = await gists.edit('b1c0c984ef7dc1d6a292c2609d8f1818', { | |
description: `Old Navy: ${name} • ${currentPrice}`, | |
files: { | |
'db.json': { | |
content: JSON.stringify({ name, price: currentPrice, url, date: new Date().toISOString() }, null, 2), | |
}, | |
}, | |
}); | |
} catch (e) { | |
console.error(e); | |
} | |
})(); |
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
{ | |
"name": "old-navy-mlb-shirt", | |
"version": "1.0.0", | |
"description": "Trigger an IFTTT notification if the price of my favorite shirt changes.", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "John Flesch <john@fles.ch> (https://fles.ch)", | |
"license": "MIT", | |
"dependencies": { | |
"gists": "^2.0.0", | |
"jsdom": "^12.0.0", | |
"node-ifttt-maker": "^1.0.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment