forked from Seneca-CDOT/telescope
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes issue Seneca-CDOT#16, created a function to parse feed
- Loading branch information
Showing
2 changed files
with
6 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,7 @@ | ||
const FeedParser = require('feedparser'); | ||
const bent = require('bent'); | ||
const feedparser = require('feedparser-promised'); | ||
|
||
// feed: url feed | ||
// Accepts a url feed and parses it, on success will return the stream | ||
module.exports = async function(feed){ | ||
const feedparser = new FeedParser(); | ||
const getStream = bent(feed); | ||
|
||
let stream = await getStream('/json.api'); | ||
return new Promise((resolve,reject)=>{ | ||
stream.pipe(feedparser) | ||
.on('error', reject) | ||
.on('readable', resolve); | ||
}) | ||
// feed: url for the feed | ||
// Accepts a url feed and parses it, on success will return a stream | ||
module.exports = async function (feed) { | ||
return feedparser.parse(feed); | ||
}; | ||
|