Last active
June 29, 2020 20:07
-
-
Save Naahuel/36094ed49ca0209ebf54ccff15674800 to your computer and use it in GitHub Desktop.
Extensión de Argos para Gnome para ver el valor del dolar desde Banco Nación
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/home/nahuel/.nvm/versions/node/v11.15.0/bin/node | |
const fetch = require('node-fetch'); | |
const fs = require('fs'); | |
const parse = require('node-html-parser').parse; | |
const notifier = require('node-notifier'); | |
const display = text => console.log(`<span> </span><span foreground="greenyellow">${text}</span>`); | |
const URL = 'http://www.bna.com.ar/Personas'; | |
const saveFile = '/home/nahuel/.config/argos-dolar.txt'; | |
fetch(URL) | |
.then(res => res.text()) | |
.then(body => { | |
const root = parse(body); | |
const billetesRow = root.querySelectorAll('#billetes tbody tr'); | |
const valorDolar = billetesRow[0].querySelectorAll('td'); | |
const precioVenta = parseFloat(valorDolar[2].text.replace(',','.')); | |
const precioSolidario = (precioVenta*1.3).toFixed(2); | |
const valorDisplay = `C/$${parseFloat(valorDolar[1].text.replace(',','.'))} V/$${precioVenta} ($${precioSolidario})`; | |
display(valorDisplay); | |
fs.readFile(saveFile, "utf8", (err, data) => { | |
if (err){ | |
fs.writeFile(saveFile, valorDisplay, (err) => { | |
if (err) throw err; | |
}); | |
} else { | |
if( data !== valorDisplay ) { | |
notifier.notify({ | |
title: "Variación del dolar!", | |
message: `${valorDisplay} (antes: ${data})` | |
}); | |
fs.writeFile(saveFile, valorDisplay, (err) => { | |
if (err) throw err; | |
}); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment