Skip to content

Instantly share code, notes, and snippets.

@Franco-Poveda
Created January 14, 2016 14:36
Show Gist options
  • Save Franco-Poveda/5ff5d994a0f632b8f928 to your computer and use it in GitHub Desktop.
Save Franco-Poveda/5ff5d994a0f632b8f928 to your computer and use it in GitHub Desktop.
Sample scraper using cheerio.js to get the next movies premiere from Cinemark Argentina, and send a PUSH campaign using the ViaCelular API every Wednesday.
var request = require('request');
var cheerio = require('cheerio');
var schedule = require('node-schedule');
var trim = require('trim');
var names =[],
dates =[];
j = schedule.scheduleJob('0 20 * * 4', function(){
request('http://www.cinemark.com.ar/ajaxCartelera.aspx?filter=Proximos', function (error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
$('div.title').each(function(i, element){
var a = $(this);
names.push(trim(a.text()));
});
$('div.actions').each(function(i, element){
var a = $(this);
dates.push(trim(a.text()));
});
sendCampain('Mañana '+ dates[0]+' '+names[0] +', no te la pierdas!');
}
});
});
var sendCampain =function (msg) {
// Armamos el request a la API de via celular:
var payload = {
'list':'default',
'type': 'ESTRENO',
'msg': msg,
'ttd': 0,
'flags': 1
}
// endpoint:
url = 'https://api.viacelular.com/v1/messages/campaign';
// Mandamos request:
request({
url: url,
method:'POST',
headers:{
'content-type': 'application/json',
'Authorization':'Bearer 59653c11e4196921aac815f3861afcbf6b6asas34nskdmnaso2asas7e2ff23640'
},
json: payload
}, function (error, response, body) {
(!error && response.statusCode === 200)?console.log(body):console.log(error);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment