From 87f98af3f6457456d7c82ce2141f04c9125d5e85 Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Fri, 19 Feb 2016 17:18:02 +0000 Subject: [PATCH] updated work calendar link --- lib/calHandler.js | 14 ++++---------- lib/caltest.js | 36 +++--------------------------------- lib/swedishword.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ lib/today.js | 11 +++++++++++ package.json | 3 ++- 5 files changed, 65 insertions(+), 44 deletions(-) create mode 100644 lib/swedishword.js diff --git a/lib/calHandler.js b/lib/calHandler.js index bd2a142..4656e13 100644 --- a/lib/calHandler.js +++ b/lib/calHandler.js @@ -19,7 +19,8 @@ function processICAL(ical) { summaryID: 'SUMMARY:', begin: 'BEGIN:VEVENT', end: 'END:VEVENT', - beginAlarm: 'BEGIN:VALARM' + beginAlarm: 'BEGIN:VALARM', + recur : 'RRULE' }; function processBlock(block) { @@ -109,7 +110,7 @@ module.exports = { jsonBlock: [], getTodaysSimple: function () { "use strict"; - logger.info('+ getTodaysMeetings'); + logger.info('+ getTodaysSimple'); var today = { entries: [] }; @@ -121,7 +122,7 @@ module.exports = { } } // logger.debug(today); - logger.info('- getTodaysMeetings'); + logger.info('- getTodaysSimple'); return today; }, getTodaysMeetings: function () { @@ -181,10 +182,3 @@ module.exports = { * Created by Martin on 16/02/2016. */ }; - -/*module.exports.getSimpleCalV2('http://www.pogdesign.co.uk/cat/download_ics/60cfdff469d0490545d33d7e3b5c0bcc', function (v) { - console.log(v); -});*/ - -// https://calendar.google.com/calendar/ical/martind2000%40gmail.com/private-40cfebc9f7dcfa7fde6b9bf2f0092c93/basic.ics -// http://www.pogdesign.co.uk/cat/download_ics/60cfdff469d0490545d33d7e3b5c0bcc diff --git a/lib/caltest.js b/lib/caltest.js index 3739495..ba19f20 100644 --- a/lib/caltest.js +++ b/lib/caltest.js @@ -1,7 +1,7 @@ /** * Created by Martin on 15/02/2016. */ -var http = require('http'), request = require('request'), ical2json = require('ical2json'), util = require('util'); +var http = require('http'), request = require('request'), calHandler = require('./calHandler'), util = require('util'); var jsonfile = require('jsonfile'); var log4js = require('log4js'); var logger = log4js.getLogger(); @@ -17,39 +17,9 @@ function saveData(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]; + calHandler.getSimpleCalV2('https://www.tripit.com/feed/ical/private/DB96E4BB-94A9BD8F9CC1CF51C6CC0D920840F4F5/tripit.ics', function(v) { + logger.debug(v) ; }); } diff --git a/lib/swedishword.js b/lib/swedishword.js new file mode 100644 index 0000000..1d679ce --- /dev/null +++ b/lib/swedishword.js @@ -0,0 +1,45 @@ +/** + * Created by Martin on 15/02/2016. + */ +var http = require('http'), request = require('request'), util = require('util'); +var jsonfile = require('jsonfile'); +var log4js = require('log4js'); +var logger = log4js.getLogger(); +var to_json = require('xmljson').to_json; + +require('sugar-date'); + + +var file = __dirname + '/' + 'cal.json'; + +function saveData(v) { + jsonfile.writeFileSync(file, v); +} + +module.exports = { + getSwedishWord: function (cb) { + + var t= new Date(), ms = t.getTime(); + + + url = ['http://wotd.transparent.com/rss/swedish-widget.xml?t=', ms].join(''); + logger.info(url); + request(url, function (err, resp, body) { + if (err) + throw err; + + logger.debug(body); + + to_json(body, function (error, data) { + console.log(data); + if(typeof cb === 'function') { + cb(data); + } + }); + + }); + + } +}; + +module.exports.getSwedishWord(); \ No newline at end of file diff --git a/lib/today.js b/lib/today.js index a5ea7ee..7138cf9 100644 --- a/lib/today.js +++ b/lib/today.js @@ -350,9 +350,20 @@ module.exports = { logger.error(e); } + try { + calHandler.getSimpleCalV2('https://www.tripit.com/feed/ical/private/DB96E4BB-94A9BD8F9CC1CF51C6CC0D920840F4F5/tripit.ics', function(v) { + todayCache.data.cal.entries = todayCache.data.cal.entries.concat(v.entries) ; + }); + } + catch (e) { + logger.error(e); + } + // word of the day http://wotd.transparent.com/rss/swedish-widget.xml?t=1455840000000 + // time stamp + } } ; diff --git a/package.json b/package.json index b309259..10ea36f 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "mammoth": "^0.3.25-pre.1", "request": "^2.67.0", "simple-weather": "^1.2.2", - "wordsoap": "^0.2.0" + "wordsoap": "^0.2.0", + "xmltojson": "^1.1.0" }, "dependencies": { "elapsed": "0.0.7",