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 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # FeedMe.js
  2. feedme.js is an RSS/Atom/JSON feed parser. How is this different from the other few feed parsers? It uses [sax-js](https://github.com/isaacs/sax-js) for xml parsing and [clarinet](https://github.com/dscape/clarinet) for json parsing. That means it is coded in pure Javascript and thus more deployable. I needed a parser that wouldn't require me to install external dependencies or to compile anything.
  3. ![Depfu](https://img.shields.io/depfu/fent/feedme.js)
  4. [![codecov](https://codecov.io/gh/fent/feedme.js/branch/master/graph/badge.svg)](https://codecov.io/gh/fent/feedme.js)
  5. # Usage
  6. ```js
  7. const FeedMe = require('feedme');
  8. const http = require('http');
  9. http.get('http://www.npr.org/rss/rss.php?id=1001', (res) => {
  10. if (res.statusCode != 200) {
  11. console.error(new Error(`status code ${res.statusCode}`));
  12. return;
  13. }
  14. let parser = new FeedMe();
  15. parser.on('title', (title) => {
  16. console.log('title of feed is', title);
  17. });
  18. parser.on('item', (item) => {
  19. console.log();
  20. console.log('news:', item.title);
  21. console.log(item.description);
  22. });
  23. res.pipe(parser);
  24. });
  25. ```
  26. # API
  27. ### new FeedMe([buffer])
  28. Creates a new instance of the FeedMe parser. `buffer` can be `true` if you want the parser to buffer the entire feed document as a JSON object, letting you use the `FeedMe#done()` method.
  29. ### parser.write(xml)
  30. Write to the parser.
  31. ### parser.done()
  32. Can only be used if `buffer` is `true`. It returns the feed as a Javascript object, should be called after `end` is emitted from the parser. Subelements are put as children objects with their names as keys. When one object has more than one child of the same name, they are put into an array. Items are always put into an array.
  33. ```js
  34. const FeedMe = require('feedme');
  35. const http = require('http');
  36. http.get('https://nodejs.org/en/feed/blog.xml', (res) => {
  37. let parser = new FeedMe(true);
  38. res.pipe(parser);
  39. parser.on('finish', () => {
  40. console.log(parser.done());
  41. });
  42. });
  43. ```
  44. An example of what `parser.done()` could return.
  45. ```js
  46. {
  47. type: 'rss 2.0',
  48. title: 'Liftoff News',
  49. link: 'http://liftoff.msfc.nasa.gov/',
  50. description: 'Liftoff to Space Exploration.',
  51. language: 'en-us',
  52. pubdate: 'Tue, 10 Jun 2003 04:00:00 GMT',
  53. lastbuilddate: 'Tue, 10 Jun 2003 09:41:01 GMT',
  54. docs: 'http://blogs.law.harvard.edu/tech/rss',
  55. generator: 'Weblog Editor 2.0',
  56. managingeditor: 'editor@example.com',
  57. webmaster: 'webmaster@example.com',
  58. items: [
  59. {
  60. title: 'Star City',
  61. link: 'http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp',
  62. description: 'How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia\'s <a href="http://howe.iki.rssi.ru/GCTC/gctc_e.htm">Star City</a>.',
  63. pubdate: 'Tue, 03 Jun 2003 09:39:21 GMT',
  64. guid: 'http://liftoff.msfc.nasa.gov/2003/06/03.html#item573'
  65. },
  66. {
  67. description: 'Sky watchers in Europe, Asia, and parts of Alaska and Canada will experience a <a href="http://science.nasa.gov/headlines/y2003/30may_solareclipse.htm">partial eclipse of the Sun</a> on Saturday, May 31st.',
  68. pubdate: 'Fri, 30 May 2003 11:06:42 GMT',
  69. guid: 'http://liftoff.msfc.nasa.gov/2003/05/30.html#item572' },
  70. {
  71. title: 'The Engine That Does More',
  72. link: 'http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp',
  73. description: 'Before man travels to Mars, NASA hopes to design new engines that will let us fly through the Solar System more quickly. The proposed VASIMR engine would do that.',
  74. pubdate: 'Tue, 27 May 2003 08:37:32 GMT',
  75. guid: 'http://liftoff.msfc.nasa.gov/2003/05/27.html#item571' },
  76. {
  77. title: 'Astronauts\' Dirty Laundry',
  78. link: 'http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp',
  79. description: 'Compared to earlier spacecraft, the International Space Station has many luxuries, but laundry facilities are not one of them. Instead, astronauts have other options.',
  80. pubdate: 'Tue, 20 May 2003 08:56:02 GMT',
  81. guid: 'http://liftoff.msfc.nasa.gov/2003/05/20.html#item570' }
  82. ]
  83. }
  84. ```
  85. ### Event: 'item'
  86. * `Object` - Item from the feed.
  87. Emitted whenever the parser finds a new feed item. An item can be inside an `<item>` or <entry>` tag.
  88. ### Event: `tagname`
  89. * `Object` - The object containing the value of the tag found.
  90. Emitted whenever a tag on the root of the document is finished parsing. The root being the `<channel>` or `<feed>` tag. Example:
  91. ```js
  92. parser.on('description', (d) => {
  93. // do something
  94. });
  95. ```
  96. ### Event: 'type'
  97. * `string` - Type of feed. Example: atom, rss 2.0, json.
  98. ### Event: 'error'
  99. * `Error`
  100. Emitted when there is an error parsing the document.
  101. # Install
  102. npm install feedme
  103. # Tests
  104. Tests are written with [mocha](https://mochajs.org)
  105. ```bash
  106. npm test
  107. ```