Skip to content

Instantly share code, notes, and snippets.

Created February 12, 2012 17:12
Show Gist options
  • Save anonymous/1809681 to your computer and use it in GitHub Desktop.
Save anonymous/1809681 to your computer and use it in GitHub Desktop.
ePirat - pastebin.com/L9P7vTVN
var http = require('http');
var url = require('url');
var accumulate = new Object;
var Boxcar = [];
var notifo = [];
accumulate.events = [];
var counter = 9;
// Configuration
// Interval to check if liveshow starts in 15 Minutes
var myIntervalTime = 1;
// URL where the iCal File is located
//var iCalURL = "https://www.google.com/calendar/ical/calendar%40hoersuppe.de/public/basic.ics";
var iCalURL = "https://www.google.com/calendar/ical/avicuh55tb8q9i3nhr9c83h31s%40group.calendar.google.com/public/basic.ics";
// Boxcar provider key
Boxcar.provider_key = "xyz";
// Boxcar provider secret
Boxcar.provider_secret = "xyz";
// Notifo user
notifo.user = "xyz";
// Notifo secret
notifo.secret = "xyz";
// Log level (DEBUG, INFO, ERROR)
var log_level = "DEBUG";
// Configuration end
var myInterval = setInterval(function(){
var response = '';
counter += 1;
if (counter == 10){
counter = 0;
// Download iCal File
iCalURL = url.parse(iCalURL);
Log("INFO", "Refreshing iCalender File ("+iCalURL.href+")");
http.get({host: iCalURL.hostname, port: 80, path: iCalURL.pathname}, function(res){
Log("DEBUG", "HTTP-Status: "+res.statusCode);
// Check if statusCode is not 200 (no success) and skip
if (res.statusCode !== 200){
Log("ERROR", "Could not load iCal File, HTTP-Status: "+res.statusCode);
return;
}
res.setEncoding('utf-8');
// Collect data
res.on('data', function(chunk){
response += chunk;
});
// until stream is closed (EOF)
res.on('end', function(){
var name;
var value;
var eventnr = 0;
var isevent = false;
// Split on every newline character
data = response;
data = data.split(/[\r\n]+/);
// Log("DEBUG", "Data: "+data);
// Go through the document, line by line and check tags
for (i=0;i<=data.length-1;i++){
if (i == 0){
// Check if it's a valid iCal File and not some garbage
if (data[i] != 'BEGIN:VCALENDAR'){
Log("ERROR", "Unexpected iCal BEGIN-tag: "+data[i]);
return;
}
} else
if (data[i] == 'BEGIN:VEVENT'){
isevent = true;
accumulate.events[eventnr] = new Object;
} else
if (data[i] == 'END:VEVENT'){
eventnr = eventnr + 1;
isevent = false;
} else {
value = data[i].split(":");
name = value[0];
value.splice(0,1);
value = value.join(":");
while ( (typeof(data[i+1]) != 'undefined') && (data[i+1][0] == ' ')){
value = value + data[i+1].substring(1, data[i+1].length);
i = i+1;
}
if ( (name == "DTSTART") || (name == "CREATED")){
var d = new Date(value.substr(0,4), value.substr(4,2), value.substr(6,2), value.substr(9,2), value.substr(11,2), value.substr(13,2), 0);
value = d;
}
if ( (name != '') && (value != '') ){
if (isevent){
accumulate.events[eventnr][name] = value;
} else {
accumulate[name] = value;
}
}
}
}
PushPushRevenge(accumulate);
});
});
} else {
Log("DEBUG", typeof accumulate);
PushPushRevenge(accumulate);
}
}, myIntervalTime*60*1000);
function PushPushRevenge(calobj){
var future = new Date();
var futurem = new Date();
future.setMinutes(future.getMinutes()+15);
futurem.setMinutes(futurem.getMinutes()+16);
for (var k in calobj.events) {
var start = calobj.events[k].DTSTART;
var created = calobj.events[k].CREATED;
Log("DEBUG", "Start: "+start);
Log("DEBUG", future);
Log("DEBUG", "future: "+future.getTime());
Log("DEBUG", "start: "+start.getTime());
Log("DEBUG", "futurem: "+futurem.getTime());
if ( (start.getTime() > future.getTime()) && (start.getTime() < futurem.getTime()) ){
PushBoxcar(calobj.events[k].SUMMARY, calobj.events[k].DESCRIPTION, calobj.events[k].LOCATION); //SUMMARY DESCRIPTION LOCATION
}
}
}
function Log(level, msg){
if (log_level == "DEBUG"){
if ( (level == "DEBUG") || (level == "INFO") || (level == "ERROR") ){
console.log(msg);
return;
}
}
if (log_level == "INFO"){
if ( (level == "INFO") || (level == "ERROR") ){
console.log(msg);
return;
}
}
if (log_level == "ERROR"){
if ( (level == "ERROR") ){
console.log(msg);
return;
}
}
}
function PushBoxcar(name, message, url){
// TODO: do stuff
Log("DEBUG", "Name: "+name);
Log("DEBUG", "Message: "+message);
Log("DEBUG", "URL: "+url);
}
function PushNotifo(){
// TODO: do stuff
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment