Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 182 additions & 0 deletions chapter2/sample/data/feeds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
[
{
"site": "npr",
"link": "http://www.npr.org/rss/rss.php?id=1001",
"type": "rss"
},
{
"site": "npr",
"link": "http://www.npr.org/rss/rss.php?id=1008",
"type": "rss"
},
{
"site": "npr",
"link": "http://www.npr.org/rss/rss.php?id=1006",
"type": "rss"
},
{
"site": "npr",
"link": "http://www.npr.org/rss/rss.php?id=1007",
"type": "rss"
},
{
"site": "npr",
"link": "http://www.npr.org/rss/rss.php?id=1057",
"type": "rss"
},
{
"site": "npr",
"link": "http://www.npr.org/rss/rss.php?id=1021",
"type": "rss"
},
{
"site": "npr",
"link": "http://www.npr.org/rss/rss.php?id=1012",
"type": "rss"
},
{
"site": "npr",
"link": "http://www.npr.org/rss/rss.php?id=1003",
"type": "rss"
},
{
"site": "npr",
"link": "http://www.npr.org/rss/rss.php?id=2",
"type": "rss"
},
{
"site": "npr",
"link": "http://www.npr.org/rss/rss.php?id=3",
"type": "rss"
},
{
"site": "npr",
"link": "http://www.npr.org/rss/rss.php?id=5",
"type": "rss"
},
{
"site": "npr",
"link": "http://www.npr.org/rss/rss.php?id=13",
"type": "rss"
},
{
"site": "npr",
"link": "http://www.npr.org/rss/rss.php?id=46",
"type": "rss"
},
{
"site": "npr",
"link": "http://www.npr.org/rss/rss.php?id=7",
"type": "rss"
},
{
"site": "npr",
"link": "http://www.npr.org/rss/rss.php?id=10",
"type": "rss"
},
{
"site": "npr",
"link": "http://www.npr.org/rss/rss.php?id=39",
"type": "rss"
},
{
"site": "npr",
"link": "http://www.npr.org/rss/rss.php?id=43",
"type": "rss"
},
{
"site": "bbci",
"link": "http://feeds.bbci.co.uk/news/rss.xml",
"type": "rss"
},
{
"site": "bbci",
"link": "http://feeds.bbci.co.uk/news/business/rss.xml",
"type": "rss"
},
{
"site": "bbci",
"link": "http://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml",
"type": "rss"
},
{
"site": "cnn",
"link": "http://rss.cnn.com/rss/cnn_topstories.rss",
"type": "rss"
},
{
"site": "cnn",
"link": "http://rss.cnn.com/rss/cnn_world.rss",
"type": "rss"
},
{
"site": "cnn",
"link": "http://rss.cnn.com/rss/cnn_us.rss",
"type": "rss"
},
{
"site": "cnn",
"link": "http://rss.cnn.com/rss/cnn_allpolitics.rss",
"type": "rss"
},
{
"site": "cnn",
"link": "http://rss.cnn.com/rss/cnn_crime.rss",
"type": "rss"
},
{
"site": "cnn",
"link": "http://rss.cnn.com/rss/cnn_tech.rss",
"type": "rss"
},
{
"site": "cnn",
"link": "http://rss.cnn.com/rss/cnn_health.rss",
"type": "rss"
},
{
"site": "foxnews",
"link": "http://feeds.foxnews.com/foxnews/opinion?format=xml",
"type": "rss"
},
{
"site": "foxnews",
"link": "http://feeds.foxnews.com/foxnews/politics?format=xml",
"type": "rss"
},
{
"site": "foxnews",
"link": "http://feeds.foxnews.com/foxnews/national?format=xml",
"type": "rss"
},
{
"site": "foxnews",
"link": "http://feeds.foxnews.com/foxnews/world?format=xml",
"type": "rss"
},
{
"site": "nbcnews",
"link": "http://feeds.nbcnews.com/feeds/topstories",
"type": "rss"
},
{
"site": "nbcnews",
"link": "http://feeds.nbcnews.com/feeds/usnews",
"type": "rss"
},
{
"site": "nbcnews",
"link": "http://rss.msnbc.msn.com/id/21491043/device/rss/rss.xml",
"type": "rss"
},
{
"site": "nbcnews",
"link": "http://rss.msnbc.msn.com/id/21491571/device/rss/rss.xml",
"type": "rss"
},
{
"site": "nbcnews",
"link": "http://rss.msnbc.msn.com/id/28180066/device/rss/rss.xml",
"type": "rss"
}
]
23 changes: 23 additions & 0 deletions chapter2/sample/data/fetchFeeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Parser from 'rss-parser';
import fs from 'fs';

const parser = new Parser();

// Soma feeds.json
const feeds = JSON.parse(fs.readFileSync('feeds.json', 'utf-8'));

async function fetchAllFeeds() {
for (const feed of feeds) {
try {
const rss = await parser.parseURL(feed.link);
console.log(`\nLatest posts from ${feed.site}:`);
rss.items.forEach(item => {
console.log(`- ${item.title} (${item.link})`);
});
} catch (err) {
console.log(`Error fetching ${feed.site}:`, err.message);
}
}
}

fetchAllFeeds();