Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. # node-ical
  2. [![Build](https://github.com/jens-maus/node-ical/workflows/CI/badge.svg)](https://github.com/jens-maus/node-ical/actions)
  3. [![NPM version](https://img.shields.io/npm/v/node-ical.svg)](https://www.npmjs.com/package/node-ical)
  4. [![Downloads](https://img.shields.io/npm/dm/node-ical.svg)](https://www.npmjs.com/package/node-ical)
  5. [![Contributors](https://img.shields.io/github/contributors/jens-maus/node-ical.svg)](https://github.com/jens-maus/node-ical/graphs/contributors)
  6. [![License](https://img.shields.io/github/license/jens-maus/node-ical.svg)](https://github.com/jens-maus/node-ical/blob/master/LICENSE)
  7. [![Donate](https://img.shields.io/badge/donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RAQSDY9YNZVCL)
  8. [![GitHub stars](https://img.shields.io/github/stars/jens-maus/node-ical.svg?style=social&label=Star)](https://github.com/jens-maus/node-ical/stargazers/)
  9. [![NPM](https://nodei.co/npm/node-ical.png?downloads=true)](https://nodei.co/npm/node-ical/)
  10. A minimal iCalendar/ICS (http://tools.ietf.org/html/rfc5545) parser for Node.js. This module is a direct fork
  11. of the ical.js module by Peter Braden (https://github.com/peterbraden/ical.js) which is primarily targeted
  12. for parsing iCalender/ICS files in a pure JavaScript environment. (ex. within the browser itself) This node-ical
  13. module however, primarily targets Node.js use and allows for more flexible APIs and interactions within a Node environment. (like filesystem access!)
  14. ## Install
  15. node-ical is availble on npm:
  16. ```sh
  17. npm install node-ical
  18. ```
  19. ## API
  20. The API has now been broken into three sections:
  21. - [sync](#sync)
  22. - [async](#async)
  23. - [autodetect](#autodetect)
  24. `sync` provides synchronous API functions.
  25. These are easy to use but can block the event loop and are not recommended for applications that need to serve content or handle events.
  26. `async` provides proper asynchronous support for iCal parsing.
  27. All functions will either return a promise for `async/await` or use a callback if one is provided.
  28. `autodetect` provides a mix of both for backwards compatibility with older node-ical applications.
  29. All API functions are documented using JSDoc in the [node-ical.js](node-ical.js) file.
  30. This allows for IDE hinting!
  31. ### sync
  32. ```javascript
  33. // import ical
  34. const ical = require('node-ical');
  35. // use the sync function parseFile() to parse this ics file
  36. const events = ical.sync.parseFile('example-calendar.ics');
  37. // loop through events and log them
  38. for (const event of Object.values(events)) {
  39. console.log(
  40. 'Summary: ' + event.summary +
  41. '\nDescription: ' + event.description +
  42. '\nStart Date: ' + event.start.toISOString() +
  43. '\n'
  44. );
  45. };
  46. // or just parse some iCalendar data directly
  47. const directEvents = ical.sync.parseICS(`
  48. BEGIN:VCALENDAR
  49. VERSION:2.0
  50. CALSCALE:GREGORIAN
  51. BEGIN:VEVENT
  52. SUMMARY:Hey look! An example event!
  53. DTSTART;TZID=America/New_York:20130802T103400
  54. DTEND;TZID=America/New_York:20130802T110400
  55. LOCATION:1000 Broadway Ave.\, Brooklyn
  56. DESCRIPTION: Do something in NY.
  57. STATUS:CONFIRMED
  58. UID:7014-1567468800-1567555199@peterbraden@peterbraden.co.uk
  59. END:VEVENT
  60. END:VCALENDAR
  61. `);
  62. // log the ids of these events
  63. console.log(Object.keys(directEvents));
  64. ```
  65. ### async
  66. ```javascript
  67. // import ical
  68. const ical = require('node-ical');
  69. // do stuff in an async function
  70. ;(async () => {
  71. // load and parse this file without blocking the event loop
  72. const events = await ical.async.parseFile('example-calendar.ics');
  73. // you can also use the async lib to download and parse iCal from the web
  74. const webEvents = await ical.async.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics');
  75. // also you can pass options to fetch() (optional though!)
  76. const headerWebEvents = await ical.async.fromURL(
  77. 'http://lanyrd.com/topics/nodejs/nodejs.ics',
  78. { headers: { 'User-Agent': 'API-Example / 1.0' } }
  79. );
  80. // parse iCal data without blocking the main loop for extra-large events
  81. const directEvents = await ical.async.parseICS(`
  82. BEGIN:VCALENDAR
  83. VERSION:2.0
  84. CALSCALE:GREGORIAN
  85. BEGIN:VEVENT
  86. SUMMARY:Hey look! An example event!
  87. DTSTART;TZID=America/New_York:20130802T103400
  88. DTEND;TZID=America/New_York:20130802T110400
  89. DESCRIPTION: Do something in NY.
  90. UID:7014-1567468800-1567555199@peterbraden@peterbraden.co.uk
  91. END:VEVENT
  92. END:VCALENDAR
  93. `);
  94. })()
  95. .catch(console.error.bind());
  96. // old fashioned callbacks cause why not
  97. // parse a file with a callback
  98. ical.async.parseFile('example-calendar.ics', function(err, data) {
  99. if (err) {
  100. console.error(err);
  101. process.exit(1);
  102. }
  103. console.log(data);
  104. });
  105. // or a URL
  106. ical.async.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics', function(err, data) { console.log(data); });
  107. // or directly
  108. ical.async.parseICS(`
  109. BEGIN:VCALENDAR
  110. VERSION:2.0
  111. CALSCALE:GREGORIAN
  112. BEGIN:VEVENT
  113. SUMMARY:Hey look! An example event!
  114. DTSTART;TZID=America/New_York:20130802T103400
  115. DTEND;TZID=America/New_York:20130802T110400
  116. DESCRIPTION: Do something in NY.
  117. UID:7014-1567468800-1567555199@peterbraden@peterbraden.co.uk
  118. END:VEVENT
  119. END:VCALENDAR
  120. `, function(err, data) { console.log(data); });
  121. ```
  122. ### autodetect
  123. These are the old API examples, which still work and will be converted to the new API automatically.
  124. Functions with callbacks provided will also have better performance over the older versions even if they use the old API.
  125. Parses a string with ICS content in sync. This can block the event loop on big files.
  126. ```javascript
  127. const ical = require('node-ical');
  128. ical.parseICS(str);
  129. ```
  130. Parses a string with ICS content in async to prevent the event loop from being blocked.
  131. ```javascript
  132. const ical = require('node-ical');
  133. ical.parseICS(str, function(err, data) {
  134. if (err) console.log(err);
  135. console.log(data);
  136. });
  137. ```
  138. Parses a string with an ICS file in sync. This can block the event loop on big files.
  139. ```javascript
  140. const ical = require('node-ical');
  141. const data = ical.parseFile(filename);
  142. ```
  143. Parses a string with an ICS file in async to prevent event loop from being blocked.
  144. ```javascript
  145. const ical = require('node-ical');
  146. const data = ical.parseFile(filename, function(err, data) {
  147. if (err) console.log(err);
  148. console.log(data);
  149. });
  150. ```
  151. Reads in the specified iCal file from the URL, parses it and returns the parsed data.
  152. ```javascript
  153. const ical = require('node-ical');
  154. ical.fromURL(url, options, function(err, data) {
  155. if (err) console.log(err);
  156. console.log(data);
  157. });
  158. ```
  159. Use the node-fetch library to fetch the specified URL (```opts``` gets passed on to the ```fetch()``` call), and call the function with the result. (either an error or the data)
  160. #### Example 1 - Print list of upcoming node conferences (see example.js) (parses the file synchronous)
  161. ```javascript
  162. const ical = require('node-ical');
  163. const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
  164. ical.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics', {}, function (err, data) {
  165. for (let k in data) {
  166. if (data.hasOwnProperty(k)) {
  167. const ev = data[k];
  168. if (data[k].type == 'VEVENT') {
  169. console.log(`${ev.summary} is in ${ev.location} on the ${ev.start.getDate()} of ${months[ev.start.getMonth()]} at ${ev.start.toLocaleTimeString('en-GB')}`);
  170. }
  171. }
  172. }
  173. });
  174. ```