Created
October 1, 2015 21:35
-
-
Save icaromh/7dd15bcfb5e738196489 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// #general C067W8KMX | |
// icaro U067W8YQG | |
var cheerio = require('cheerio') | |
, request = require('request') | |
, slackToken = 'xoxp-6268274772-6268304832-9597136048-0c6704' | |
, slackTarget = 'U067W8YQG' | |
; | |
if(process.argv.length < 3 || paramIsNumber() === false ){ | |
console.log('alelobot.js use: '); | |
console.log('node alelobot.js CARD_NUMBER') | |
process.exit(); | |
} | |
function paramIsNumber(){ | |
return isNaN(parseInt(process.argv[2])) === false; | |
} | |
function sendMessage(msg){ | |
request({ | |
url : 'https://slack.com/api/chat.postMessage', | |
method : 'GET', | |
qs : { | |
token : slackToken, | |
channel : slackTarget, | |
text : msg, | |
username : 'AleloBot', | |
pretty : 1, | |
icon_url : 'https://alelo.com.br/content/dam/portal/images/inicial/logo-alelo.png' | |
} | |
}, function(err, res, body){ | |
console.log(body); | |
}); | |
}; | |
function getAleloValue(cardNumber){ | |
request({ | |
headers: { | |
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36' | |
}, | |
url : "http://m.alelo.com.br/alelomobile/se.do", | |
method : 'POST', | |
form : { | |
cartao : cardNumber | |
} | |
}, function(err, res, body){ | |
if(!err){ | |
var $ = cheerio.load(body) | |
, saldo = $('#saldoDisp .valor').text() | |
, $infoAdic = $('#infoAdic table tr') | |
, msg; | |
msg = "Olá amiguinho :) \n"; | |
msg += "Saldo disponível: " + saldo + "\n"; | |
$infoAdic.each(function(index, tr) { | |
msg += $(tr).find('.rotulo').text(); | |
msg += $(tr).find('.valor').text() + "\n"; | |
}); | |
sendMessage(msg); | |
} | |
}); | |
} | |
getAleloValue(process.argv[2]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment