Created
October 13, 2016 12:12
-
-
Save coreequip/84d5704ddfb3b8ece7df903bbf51704e to your computer and use it in GitHub Desktop.
Cyberport Cybersale PushBullet PushOver Google Script π
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
function fetchSale() { | |
var xml = UrlFetchApp.fetch('https://www.cyberport.de/feed.php?ft=NEWS&ff=rss').getContentText(); | |
var root = XmlService.parse(xml).getRootElement(); | |
var entries = root.getChild('channel').getChildren('item'); | |
var res = ''; | |
entries.forEach(function(el){ | |
if (el.getChild('link').getText() != 'https://www.cyberport.de/cybersale') return; | |
var diff = (new Date()).getTime() - (new Date(el.getChild('pubDate').getText())).getTime() | |
if (diff > 864e5) return; | |
res = el.getChild('title').getText(); | |
}); | |
return res; | |
} | |
function pushCyberSalePushbullet() { | |
var res = UrlFetchApp.fetch('https://api.pushbullet.com/v2/pushes', { | |
headers: {'Access-Token': PropertiesService.getScriptProperties().getProperty('access_token')}, | |
method: 'POST', | |
payload: JSON.stringify({ | |
"device_iden": PropertiesService.getScriptProperties().getProperty('device_id'), | |
"type": "link", | |
"title": "Cybersale", | |
"body": fetchSale(), | |
"url":"https://www.cyberport.de/cybersale" | |
}), | |
contentType: 'application/json' | |
}); | |
Logger.log(res); | |
} | |
function pushCyberSalePushOver() { | |
var res = UrlFetchApp.fetch('https://api.pushover.net/1/messages.json', { | |
method: 'POST', | |
contentType: 'application/x-www-form-urlencoded', | |
payload: 'token=' + PropertiesService.getScriptProperties().getProperty('pushover_token') + | |
'&user=' + PropertiesService.getScriptProperties().getProperty('pushover_userkey') + | |
'&title=Cybersale' + | |
'&message=' + encodeURIComponent(fetchSale())+ | |
'&url=https://www.cyberport.de/cybersale&url_title=Open in browser', | |
}); | |
Logger.log(res); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment