-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprices.js
41 lines (35 loc) · 1.23 KB
/
prices.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
const arvish = require('arvish');
const cheerio = require('cheerio');
const got = require('got');
const priceAPI = `https://eshop-prices.com/{query}?currency=${process.env.currency}`;
got(priceAPI.replace('{query}', arvish.input), {
headers: {
'Content-Type': 'text/html; charset=utf-8',
'Accept': '*/*',
"Accept-Encoding": "gzip, deflate, br",
'Connection': 'gzip, deflate, br',
'Cache-Control': 'no-cache'
}
}).then((html) => {
const items = [];
const $ = cheerio.load(html.body);
const listElems = $('.pointer').children('.price-value');
for (const elem of listElems) {
const country = $(elem.parent.children[3]).text().trim();
const price = $(elem).text().trim();
if (price.includes(' ')) {
const [originalPrice, ...others] = price.split(' ');
const discountedPrice = others.join(' ');
items.push({
title: `[${country}] [🎉 On SALE] ${originalPrice} -> ${discountedPrice}`,
arg: discountedPrice
})
} else {
items.push({
title: `[${country}] ${price}`,
arg: price
})
}
}
arvish.output(items);
});