/** * Created by Martin on 15/02/2016. */ var http = require('http'), request = require('request'), ical2json = require('ical2json'), util = require('util'); var jsonfile = require('jsonfile'); var log4js = require('log4js'); var logger = log4js.getLogger(); require('sugar-date'); var file = __dirname + '/' + 'cal.json'; function saveData(v) { jsonfile.writeFileSync(file, v); } module.exports = { getCal: function () { var url = 'https://calendar.google.com/calendar/ical/martind2000%40gmail.com/private-40cfebc9f7dcfa7fde6b9bf2f0092c93/basic.ics'; request(url, function (err, resp, body) { if (err) throw err; var output = ical2json.convert(body); // saveData(output); for (var i = 0; i < output.VCALENDAR[0].VEVENT.length; i++) { var item = output.VCALENDAR[0].VEVENT[i]; var d; if (item.hasOwnProperty('DTSTART')) { d = Date.create(item.DTSTART); } else { d = Date.create(item['DTSTART;VALUE=DATE']); } if (d.getFullYear() == 2016) { logger.debug(item); //console.log(item['SUMMARY']); } } // console.log(util.inspect(output)); // output.VCALENDAR.VEVENT[1]; }); } }; module.exports.getCal();