Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * BuzzfeedController
- *
- * @description :: Server-side logic for managing buzzfeeds
- * @help :: See http://links.sailsjs.org/docs/controllers
- */
- module.exports = {
- buzzy: function (req, res) {
- var FeedParser = require('feedparser'),
- request = require('request');
- var req = request('http://www.buzzfeed.com/index.xml'),
- feedparser = new FeedParser();
- req.on('error', function (error) {
- // handle any request errors
- });
- req.on('response', function (res) {
- var stream = this;
- if (res.statusCode != 200) return this.emit('error', new Error('Bad status code'));
- stream.pipe(feedparser);
- });
- feedparser.on('error', function (error) {
- // always handle errors
- });
- feedparser.on('readable', function () {
- // This is where the action is!
- var stream = this,
- meta = this.meta // **NOTE** the "meta" is always available in the context of the feedparser instance
- ,
- item;
- while (item = stream.read()) {
- Buzzfeed.find({
- 'title': {
- 'contains': item.title
- }
- }).exec(function (err, data) {
- console.log(data);
- });
- }
- });
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement