How to use node-ical - 10 common examples

To help you get started, we’ve selected a few node-ical examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github grover / homebridge-calendar / src / CalendarPoller.js View on Github external
_loadCalendar() {
    // TODO: Make use of HTTP cache control stuff
    this.log(`Updating calendar ${this.name}`);
    ical.fromURL(this._url, {}, (err, cal) => {
      if (err) {
        this.log(`Failed to load iCal calender: ${this.url} with error ${err}`);
        this.emit('error', err);
      }

      if (cal) {
        this.emit('data', cal);
      }

      this._scheduleNextIteration();
    });
  }
github sedenardi / node-caldav-adapter / src / common / parseBody.js View on Github external
module.exports = async function(ctx) {
  ctx.request.body = await raw(ctx.req, {
    encoding: true,
    limit: '1mb' // practical
  });

  if (ctx.request.type.includes('xml')) {
    ctx.request.xml = new DOMParser().parseFromString(ctx.request.body);
  } else if (ctx.request.type === 'text/calendar') {
    ctx.request.ical = ical.parseICS(ctx.request.body);
  }
};
github iobroker-community-adapters / ioBroker.ical / main.js View on Github external
getICal(urlOrFile, user, pass, sslignore, calName, (err, _data) => {
        if (err || !_data) {
            adapter.log.warn('Error reading "' + urlOrFile + '": ' + err);
            cb(calName);
            return;
        }

        adapter.log.debug('File read successfully ' + urlOrFile);

        let data;
        try {
            data = ical.parseICS(_data, (err, data) => {
                if (data) {
                    adapter.log.info('processing URL: ' + calName + ' ' + urlOrFile);
                    adapter.log.debug(JSON.stringify(data));
                    const realnow    = new Date();
                    const today      = new Date();
                    today.setHours(0, 0, 0, 0);
                    const endpreview = new Date();
                    endpreview.setDate(endpreview.getDate() + parseInt(adapter.config.daysPreview, 10));

                    const now2 = new Date();

                    // clear time
                    now2.setHours(0, 0, 0, 0);

                    setImmediate(() =>
                        processData(data, realnow, today, endpreview, now2, calName, filter, cb));
github Giveth / giveth-bot / chatbot.js View on Github external
if (message[1] === ' ') {
      message = message.replace(' ', '')
    }
    message = message.split(' ')
    const cmd = message[0]
    let localHashtag = ''
    if (message.length > 1) {
      localHashtag = message[1].toLowerCase()
    }
    const user = event.getSender()
    const roomId = room.roomId
    if (cmd === '!calendar' || cmd === '!cal') {
      if (localHashtag.length == 0 && hashtagMappings.hasOwnProperty(roomId)) {
        localHashtag = hashtagMappings[roomId]
      }
      ical.fromURL(calendarURL, {}, function(err, data) {
        if (!err) {
          const today = new Date()
          const upperLimit = new Date()
          upperLimit.setDate(today.getDate() + calendarUpperLimitInMonths * 30)
          const globalFormattingOptions = {
            weekday: 'long',
            year: 'numeric',
            month: 'long',
            day: 'numeric',
          }
          globals = []
          locals = []
          for (var key in data) {
            if (data.hasOwnProperty(key) && data[key].start && data[key].end) {
              if (data[key].rrule && data[key].start.tz) {
                var nextOccurrences = data[key].rrule.between(
github naimo84 / node-red-contrib-ical-events / src / caldav.ts View on Github external
for (let calendarObject of calendarEntry.calendar.objects) {
                                        if (calendarObject.data && calendarObject.data.href) {
                                            let ics = url.origin + calendarObject.data.href;
                                            let header = {};
                                            let username = node.config.username;
                                            let password = node.config.password;
                                            if (username && password) {
                                                var auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');
                                                header = {
                                                    headers: {
                                                        'Authorization': auth
                                                    }
                                                }
                                            }

                                           return ical.fromURL(ics, header).then(data => {
                                                for (var k in data) {
                                                    var ev = data[k];
                                                    ev.calendarName = calendar.displayName;
                                                    retEntries[ev.uid] = ev;
                                                }                                              
                                                return retEntries;
                                            });
                                        }
                                    }
                                }
                            }
                        })
                    );
github naimo84 / node-red-contrib-ical-events / dist / caldav.js View on Github external
for (var _a = 0, _b = calendarEntry.calendar.objects; _a < _b.length; _a++) {
                                var calendarObject = _b[_a];
                                if (calendarObject.data && calendarObject.data.href) {
                                    var ics = url.origin + calendarObject.data.href;
                                    var header = {};
                                    var username = node.config.username;
                                    var password = node.config.password;
                                    if (username && password) {
                                        var auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');
                                        header = {
                                            headers: {
                                                'Authorization': auth
                                            }
                                        };
                                    }
                                    return ical.fromURL(ics, header).then(function (data) {
                                        for (var k in data) {
                                            var ev = data[k];
                                            ev.calendarName = calendar.displayName;
                                            retEntries[ev.uid] = ev;
                                        }
                                        return retEntries;
                                    });
                                }
                            }
                        }
                    }
                }));
            }
github naimo84 / node-red-contrib-ical-events / dist / helper.js View on Github external
});
    }
    else {
        if (urlOrFile.match(/^https?:\/\//)) {
            var header = {};
            var username = node.config.username;
            var password = node.config.password;
            if (username && password) {
                var auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');
                header = {
                    headers: {
                        'Authorization': auth
                    }
                };
            }
            ical.fromURL(node.config.url, header, function (err, data) {
                if (err) {
                    callback && callback(err, null);
                    return;
                }
                callback && callback(null, data);
            });
        }
        else {
            ical.parseFile(node.config.url, function (err, data) {
                if (err) {
                    callback && callback(err, null);
                    return;
                }
                callback && callback(null, data);
            });
        }
github naimo84 / node-red-contrib-ical-events / src / helper.ts View on Github external
} else {
        if (urlOrFile.match(/^https?:\/\//)) {
            let header = {};
            let username = node.config.username;
            let password = node.config.password;

            if (username && password) {
                var auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');
                header = {
                    headers: {
                        'Authorization': auth
                    }
                }
            }

            ical.fromURL(node.config.url, header, (err, data) => {
                if (err) {
                    callback && callback(err, null);
                    return;
                }
                callback && callback(null, data);
            });
        } else {
            ical.parseFile(node.config.url, (err, data) => {
                if (err) {
                    callback && callback(err, null);
                    return;
                }
                callback && callback(null, data);
            });
        }
    }
github awslabs / aws-delivlib / change-control-lambda / lib / time-window.ts View on Github external
export function shouldBlockPipeline(icalData: string | Buffer, now = new Date(), advanceMarginSec = 3600): CalendarEvent | undefined {
  const events: Events = ical.parseICS(icalData.toString('utf8'));
  const blocks = containingEventsWithMargin(events, now, advanceMarginSec);
  return blocks.length > 0 ? blocks[0] : undefined;
}
github naimo84 / node-red-contrib-ical-events / src / helper.ts View on Github external
header = {
                    headers: {
                        'Authorization': auth
                    }
                }
            }

            ical.fromURL(node.config.url, header, (err, data) => {
                if (err) {
                    callback && callback(err, null);
                    return;
                }
                callback && callback(null, data);
            });
        } else {
            ical.parseFile(node.config.url, (err, data) => {
                if (err) {
                    callback && callback(err, null);
                    return;
                }
                callback && callback(null, data);
            });
        }
    }

}

node-ical

NodeJS class for parsing iCalendar/ICS files

Apache-2.0
Latest version published 2 months ago

Package Health Score

84 / 100
Full package analysis