Skip to content

Commit

Permalink
Merge pull request #5 from kpman/support-atom
Browse files Browse the repository at this point in the history
Support Atom format
  • Loading branch information
kpman authored Nov 7, 2017
2 parents 08f33c9 + b043614 commit aa4e474
Show file tree
Hide file tree
Showing 3 changed files with 290 additions and 121 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@
"homepage": "https://github.com/kpman/newsroom/#readme",
"dependencies": {
"chalk": "^2.3.0",
"feed-read-parser": "^0.0.6",
"figures": "^2.0.0",
"got": "^7.1.0",
"inquirer": "^3.3.0",
"invariant": "^2.2.2",
"lodash": "^4.17.4",
"minimist": "^1.2.0",
"open": "^0.0.5",
"xml2js": "^0.4.19"
"open": "^0.0.5"
},
"devDependencies": {
"babel-eslint": "^8.0.1",
Expand Down
14 changes: 5 additions & 9 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const { promisify } = require('util');

const get = require('lodash/get');
const got = require('got');
const minimist = require('minimist');
const inquirer = require('inquirer');
const xml2js = require('xml2js');
const open = require('open');
const invariant = require('invariant');
const feed = promisify(require('feed-read-parser'));

const pkg = require('../package.json');

Expand Down Expand Up @@ -36,8 +35,6 @@ const handleRejection = err => {
process.on('unhandledRejection', handleRejection);
process.on('uncaughtException', handleUnexpected);

const parseString = promisify(xml2js.parseString);

const sourceQuestion = {
type: 'list',
name: 'source',
Expand All @@ -58,13 +55,12 @@ const getTitleQuestion = (titles, pageSize = 5) => ({
const readNews = async (source, pageSize = 5) => {
print(`Trying to fetch the ${source}'s latest news...`);
const src = await get(sources, source);
const rss = await got(src.rss);
const result = await parseString(rss.body);
const result = await feed(src.rss);

const items = {};

result.rss.channel[0].item.slice(0, pageSize).forEach(item => {
const [title] = item.title;
const [link] = item.link;
result.slice(0, pageSize).forEach(item => {
const { title, link } = item;
items[title] = link;
});

Expand Down
Loading

0 comments on commit aa4e474

Please sign in to comment.