Skip to content

Instantly share code, notes, and snippets.

@CBeloch
Last active November 6, 2017 11:41
Show Gist options
  • Save CBeloch/9b07dbbf756b21a56a20 to your computer and use it in GitHub Desktop.
Save CBeloch/9b07dbbf756b21a56a20 to your computer and use it in GitHub Desktop.
Serienplakat notifier
/*
Requires jsdom and request.
Grabs serienplakat.de to check for free posters
*/
var dom = require('jsdom');
var request = require('request');
var mainURL = 'http://serienplakat.de';
var detailURL = mainURL + '/backend/_ajax.php';
var scripts = ['http://code.jquery.com/jquery.js'];
var PUSHOVER_API = 'https://api.pushover.net/1/messages.json';
var PUSHOVER_USER = 'USER-KEY';
var PUSHOVER_APP = 'APP-KEY';
dom.env(
mainURL,
scripts,
function(error, window) {
var items = window.$('.categorie-content .item');
console.log('Found ' + items.length + ' TV Shows');
var showKeys = {};
items.each(function(){
showKeys[window.$(this).attr('data-sname')] = window.$(this).attr('data-sid')
console.log('- ' + window.$(this).attr('data-sname'))
})
console.log();
for (var showKey in showKeys) {
request.post(detailURL).form({
'cmd': 'poster',
'sId': showKeys[showKey],
'sName': showKey,
'selected': 'undefined'
}).on('response', function(response){
// Parse details
response.on('data', function(chunk) {
var posterObj = JSON.parse(chunk)
dom.env(
posterObj['data'],
scripts,
function(error, window) {
window.$('.limits').each(function(){
var availables = window.$(this).html().match(/([0-9]{1,})/g);
if (availables[0] > 0) {
console.log('POSTER AVAILABLE');
request.post(PUSHOVER_API).form({
'token': PUSHOVER_APP,
'user': PUSHOVER_USER,
'message': 'Got Posters'
});
} else {
console.log('No Poster found');
}
});
}
)
});
})
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment