Skip to content

Commit 9ee1b9c

Browse files
committed
probando con exchangemonitor
1 parent 39f5f48 commit 9ee1b9c

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

src/modules/cmd/dolar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const help = () => ({
2727
* @param { Message } message Evento completo del mensaje
2828
*/
2929
const main = async (message) => {
30-
let exchanges = await dolarService.getExchangeRates().catch((error) => {
30+
let exchanges = await dolarService.getExchangeRates(true).catch((error) => {
3131
console.log('Error en cmd dolar', error);
3232
message.channel.send('MonitorDolar dejó de funcionar... O me bloquearon, no sé.');
3333
});

src/services/dolarService.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,32 @@ const { formatNumber } = require('../utils/numbers');
1010
*/
1111
const getExchangeRates = async (useRegex = false) => {
1212
const list = [];
13-
const regexTitles = new RegExp(/(dolar\s{0,}today|bcv|airtm|binance)/, 'gi');
13+
const regexTitles = new RegExp(/(dolar\s{0,}today|bcv|airtm|binance|monitor|promedio)/, 'gi');
1414

1515
//MonitorDolar nunca ganará
16-
const browser = await puppeteer.launch({ ignoreHTTPSErrors: true });
16+
const browser = await puppeteer.launch({ headless: false, ignoreHTTPSErrors: true });
1717
const page = await browser.newPage();
18-
await page.goto('https://monitordolarvenezuela.com/', {timeout: 60000, waitUntil: 'networkidle2'});
19-
await page.waitForSelector('h3', { timeout: 5000 });
18+
await page.goto('https://exchangemonitor.net/dolar-venezuela', {timeout: 60000, waitUntil: 'networkidle2'});
19+
await page.waitForSelector('.rate-container', { timeout: 5000 });
2020

2121
const body = await page.evaluate(() => {
2222
return document.querySelector('html').innerHTML;
2323
});
2424

2525
let $ = cheerio.load(body);
2626

27-
//MonitorDolar nunca ganará
28-
$('h3').each((index, el) => {
29-
let title = $(el).first().text();
30-
let price = $(el).first().next().text();
31-
let shouldPush = true;
27+
//MonitorDolar perdió la batalla, hora de ver ExchangeMonitor
28+
$('.rate-container').each((index, el) => {
3229

33-
//MonitorDolar nunca ganará
34-
price = price.match(/([0-9]+\,[0-9]{2})/i);
35-
if (!price) {
36-
return;
37-
}
38-
price = price[0];
39-
price = price.replace(/\./g, '').replace(',', '.');
30+
let text = $(el).first().text().match(/\S+/gi);
4031

41-
title = title.replace('@','');
32+
let condition = text[1] !== "VES";
33+
34+
let title = `${text[0].replace(/\s+/gi, "")}${condition ? " "+text[1].replace(/\s+/gi, "") : ""}`
35+
let price = `${text[3 + condition]}`
36+
let shouldPush = true;
37+
price = price.replace(',', '.');
38+
title = title.trim();
4239

4340
if (useRegex && !regexTitles.test(title)) {
4441
shouldPush = false

0 commit comments

Comments
 (0)