-
Notifications
You must be signed in to change notification settings - Fork 0
/
Livelo.js
47 lines (39 loc) · 1.29 KB
/
Livelo.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
const fetch = require('node-fetch')
const cheerio = require('cheerio')
const getPrice = (csvProduct) => {
let listParceiros = {
CasasBahia: "2042780991",
FastShop: "2772514182",
Extra: "363586019",
PontoFrio: "3958921117"
}
let url;
let parceiroFilter = csvProduct['BANDEIRA'].replace(" ", "");
if(listParceiros[parceiroFilter] === undefined) {
url = encodeURI(`http://www.pontoslivelo.com.br/browse?Ntt=${csvProduct['DESCRIÇÃO']}`);
} else {
url = encodeURI(`http://www.pontoslivelo.com.br/browse?N=${listParceiros[parceiroFilter]}&Ntt=${csvProduct['DESCRIÇÃO']}`);
}
//console.log(url);
return fetch(url, { timeout: 3000 })
.then(response => response.text())
.then(body => {
let $ = cheerio.load(body)
let data = [];
$('.productdiv')
.each((key, element) => {
let pontos = $(element).find('.prodprice').text()
let nome = $(element).find('.proddesc').text()
let parceiro = $(element).find('.partner-name').text();
data.push({
nome,
pontos,
parceiro
})
});
return data[0];
});
}
module.exports = {
getPrice,
};