-
Notifications
You must be signed in to change notification settings - Fork 5
/
simple.js
44 lines (38 loc) · 1.02 KB
/
simple.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*!
* node-opmlparser
* Copyright(c) 2011-2014 Dan MacTough <[email protected]>
* MIT Licensed
*/
var OpmlParser = require('../')
, request = require('request');
var opmlparser = new OpmlParser()
, counter = 0;
var req = request('http://hosting.opml.org/dave/spec/subscriptionList.opml');
req.on('error', done);
req.on('response', function (res) {
if (res.statusCode != 200) return done(new Error('Bad status code'));
this.pipe(opmlparser);
})
opmlparser.on('error', done);
opmlparser.once('readable', function () {
console.log('This OPML is entitled: "%s"', this.meta.title);
});
opmlparser.on('readable', function() {
var outline;
while (outline = this.read()) {
if (outline['#type'] === 'feed') {
counter++;
console.log('Got feed: "%s" <%s>', outline.title, outline.xmlurl);
}
}
});
opmlparser.on('end', function () {
console.log('All done. Found %s feeds.', counter);
});
function done (err) {
if (err) {
console.log(err, err.stack);
return process.exit(1);
}
process.exit();
}