Skip to content

Commit

Permalink
Fix load URLs from file
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed Jan 26, 2024
1 parent 0ff8df3 commit 7577b8e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "git",
"url": "https://github.com/marmelab/curator-ai"
},
"version": "0.0.4",
"version": "0.0.5",
"main": "./dist/index.js",
"bin": {
"curate": "./dist/cli.js"
Expand Down
24 changes: 13 additions & 11 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,27 @@ program
.description('Read, select and summarize a list of articles')
.option('-u, --urls [urls...]', 'Wep pages to curate')
.option(
'-uf, --url-file <filename>',
'-f, --url-file <filename>',
'Text file containing a list of URLs to curate, one per line'
)
.option('-a, --aggregators [urls...]', 'Aggregator web pages to curate')
.option(
'-af, --aggregator-file <filename>',
'-F, --aggregator-file <filename>',
'Text file containing a list of aggregator URLs to curate, one per line'
)
.option('-i, --interests [interests...]', 'List of interests')
.option('-m, --max <number>', 'Max number of articles to return', '5')
.addHelpText('after', helpText)
.showHelpAfterError()
.action(async options => {
// get links from urls
let urls: string[] = options.urls || [];
if (options.urlFile) {
const linkFile = fs.readFileSync(options.urlFile, 'utf8');
urls = [...urls, ...linkFile.split('\n')];
}

// get links from aggregators
let aggregatorUrls: string[] = options.aggregators || [];
if (options.aggregatorFile) {
const aggregatorFile = fs.readFileSync(
Expand All @@ -37,11 +44,6 @@ program
);
aggregatorUrls = [...aggregatorUrls, ...aggregatorFile.split('\n')];
}
if (!urls.length && !aggregatorUrls.length) {
program.help();
}

// get links from curators
if (aggregatorUrls.length) {
const progressBar = new cliProgress.SingleBar(
{},
Expand All @@ -57,14 +59,14 @@ program
}
progressBar.stop();
}
if (options.urlFile) {
const linkFile = fs.readFileSync(options.urlFile, 'utf8');
urls = [...urls, ...linkFile.split('\n')];
}

// deduplicate urls
urls = [...new Set(urls)];

if (!urls.length) {
program.help();
}

// curate
const progressBar = new cliProgress.SingleBar(
{},
Expand Down

0 comments on commit 7577b8e

Please sign in to comment.