exports.import = function (fileName, done) { var stream = fs.createReadStream(fileName); // create parser var pr = new Parser(); // count of feeds included in the data var counter = 0; // return data var data = []; stream.on('open', function () { var self = this; self.pipe(pr); }); pr.on('readable', function () { var self = this; var outline; while ((outline = self.read()) !== null) { // add data to output array data.push(outline); // increment counter ++counter; } }); pr.on('end', function () { done(null, data); }); };
module.exports.importOpml = function (next, fn) { log.info("Importing OPML from " + fn); var subscriptions = new hp_models.SubscriptionCollection(), OpmlParser = require('opmlparser'), op = new OpmlParser(), ct = 0; op.on('feed', function (feed) { var sub = subscriptions.create({ "description": feed.title || feed.text, "resource_url": feed.xmlUrl || feed.url }); ct++; }); op.on('end', function (meta, feeds, outline) { log.info(ct + " URLs imported"); next(); }); op.parseFile(fn); };
/* 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); }) */ /* local opml */ var opmlfile = '/home/shiva/code/samiska.git/samiska/etc/feedly.opml'; var source = fs.createReadStream(opmlfile); source.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); } } });