Skip to content

Instantly share code, notes, and snippets.

@eallegretta
Last active September 27, 2022 16:48
Show Gist options
  • Save eallegretta/acf963db3f8e72fc7b84b9a9dc7078cd to your computer and use it in GitHub Desktop.
Save eallegretta/acf963db3f8e72fc7b84b9a9dc7078cd to your computer and use it in GitHub Desktop.
Verificador Stock Album Mundial en ZonaKids
const axios = require("axios");
const parser = require("node-html-parser")
const notifier = require('node-notifier');
const urls = [
"https://www.zonakids.com/productos/pack-promo-1-album-tapa-dura-100-sobres-de-figuritas-fifa-world-cup-qatar-2022/",
"https://www.zonakids.com/productos/pack-promo-1-album-50-sobres-de-figuritas-fifa-world-cup-qatar-2022/",
"https://www.zonakids.com/productos/pack-promo-1-album-100-sobres-de-figuritas-fifa-world-cup-qatar-2022/"
];
async function verifyStock(url){
const response = await axios.get(url);
const root = parser.parse(response.data);
const productName = root.querySelector("h1.product-name");
const noStock = root.querySelector(".nostock");
return { title: productName.text, stock: !noStock };
}
async function verifyStocks(){
const stockTasks = [];
for(var index = 0; index < urls.length; index++){
stockTasks.push(verifyStock(urls[index]));
}
const results = await Promise.all(stockTasks);
for(const stock of results) {
if(stock.stock){
notifier.notify(`HAY STOCK DE ${stock.title} en ${urls[index]}`);
}
}
}
setInterval(verifyStocks, 60000);
{
"name": "zonakidsscrapper",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.27.2",
"node-html-parser": "^5.4.2",
"node-notifier": "^10.0.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment