Skip to content

Instantly share code, notes, and snippets.

@Naahuel
Created November 25, 2019 01:52
Show Gist options
  • Save Naahuel/46f18322952f2750feb1e45d8028f9f1 to your computer and use it in GitHub Desktop.
Save Naahuel/46f18322952f2750feb1e45d8028f9f1 to your computer and use it in GitHub Desktop.
Gnome Argos extension - Check delivery status
#!/home/nahuel/.nvm/versions/node/v11.15.0/bin/node
# ^ replace with your own, of course
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(`<small>${text}</small> | color=orange`);
console.log('---');
};
const URL = 'https://example.com/track/12345';
const saveFile = '/home/nahuel/.config/argos-mail.txt';
# ^ replace with your own, of course
fetch(URL)
.then(res => res.text())
.then(body => {
const root = parse(body);
const estadoRow = root.querySelectorAll('.table tr');
let valorReferencia = "";
estadoRow.forEach((itemEstado, index) => {
const estado = itemEstado.querySelectorAll('td');
const valorDisplay = `${estado[0].text.replace("/2019", "")} ${estado[1].text.trim()}`;
display(valorDisplay);
if( index === 0 ){
valorReferencia = valorDisplay;
}
});
fs.readFile(saveFile, "utf8", (err, data) => {
if (err){
fs.writeFile(saveFile, valorReferencia, (err) => {
if (err) throw err;
});
} else {
if( data !== valorReferencia ) {
notifier.notify({
title: "Movimiento del paquete!",
message: valorReferencia
});
fs.writeFile(saveFile, valorReferencia, (err) => {
if (err) throw err;
});
}
}
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment