-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (70 loc) · 2.95 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const axios = require("axios");
const cheerio = require("cheerio");
const cron = require("node-cron");
const notifier = require("node-notifier");
const { URLS } = require("./constants");
async function fravega_series_x() {
const { data: htmlAsString } = await axios.get(URLS.FRAVEGA_XBOX_SERIES_X);
const parsedHtml = cheerio.load(htmlAsString);
const fravegaStockLabel = parsedHtml(
"#__next > div.withMainLayout__LayoutWrapper-sc-1lj5zpr-1.hhFziS > div > div > div.ProductDetails__NotAvailableWrapper-sc-2486oi-0.cxXFXL > section > p"
);
return fravegaStockLabel.text() !== "Producto temporalmente sin stock";
}
async function fravega_series_s() {
const { data: htmlAsString } = await axios.get(URLS.FRAVEGA_XBOX_SERIES_S);
const parsedHtml = cheerio.load(htmlAsString);
const fravegaStockLabel = parsedHtml(
"#__next > div.withMainLayout__LayoutWrapper-sc-1lj5zpr-1.hhFziS > div > div > div.generalstyles__Row-sc-1j7wv79-0.generalstyles__RowNoSpaceTopBottom-sc-1j7wv79-1.ekzajL > div > div.PurchaseInfo__PurchaseInfoWrapper-sc-1wok6te-5.cRiVbx > div.PurchaseInfo__PriceWrapper-sc-1wok6te-4.hUnqwx"
);
return fravegaStockLabel.text() !== '';
}
async function atajo_series_s() {
const { data: htmlAsString } = await axios.get(URLS.ATAJO_XBOX_SERIES_S);
const parsedHtml = cheerio.load(htmlAsString);
const atajoStockLabel = parsedHtml(
"#detalle > div.col-lg-6.col-md-6.col-sm-6.detalle_producto > h3.leyendaSinStock"
);
return atajoStockLabel.text() !== "Sin Stock";
}
async function atajo_series_x() {
const { data: htmlAsString } = await axios.get(URLS.ATAJO_XBOX_SERIES_X_KIT);
const parsedHtml = cheerio.load(htmlAsString);
const atajoStockLabel = parsedHtml(
"#detalle > div.col-lg-6.col-md-6.col-sm-6.detalle_producto > h3.leyendaSinStock"
);
return atajoStockLabel.text() !== "Sin Stock";
}
async function garbarino() {
const { data: htmlAsString } = await axios.get(URLS.GARBARINO_SERIES_S);
const parsedHtml = cheerio.load(htmlAsString);
const garbarinoStockLabel = parsedHtml(
"body > div.gb-wrapper > div.gb-products-carousel > div > div.gb-vintage-carousel-head > div.gb-vintage-carousel-head-image > span"
);
return garbarinoStockLabel.text() !== "AGOTADO";
}
async function main() {
console.log("Buscando stock cada 5 minutos...");
cron.schedule("*/5 * * * * ", async () => {
const atajoStockSeriesS = await atajo_series_s();
const atajoStockSeriesX = await atajo_series_x();
const fravegaStockX = await fravega_series_x();
const fravegaStockS = await fravega_series_s();
const garbarinoStock = await garbarino();
console.log({
Fravega: { SeriesX: fravegaStockX, SeriesS: fravegaStockS },
Atajo: { SeriesX: atajoStockSeriesX, SeriesS: atajoStockSeriesS },
Garbarino: { SeriesS: garbarinoStock },
});
if (
fravegaStockX ||
fravegaStockS ||
atajoStockSeriesS ||
atajoStockSeriesS ||
garbarinoStock
) {
notifier.notify("Hay stock!");
}
});
}
main();