bin/njtool-scrape-journal
#!/usr/bin/env node
// This file is distributed under the MIT license.
// See LICENSE file in the project root for details.
'use strict';
const program = require('commander');
const streamToString = require('stream-to-string');
const Journal = require('..').Journal;
const HELP = `
Arguments:
journal-ids List of journal IDs represented as <name>:<volume>:<issue>
`;
program
.description(
'Scrape metadata in journal pages, and output as JSON')
.option(
'--no-headless',
'Run Chromium browser in window mode for debugging')
.option(
'--no-sandbox',
'Run Chromium browser without the sandbox')
.arguments(
'[journal-ids...]')
.on('--help', () => console.log(HELP))
.action(async (ids, options) => {
if (ids.length === 0) {
const json = await streamToString(process.stdin);
ids = JSON.parse(json);
}
const metadata = await Promise.all(
Journal.from(ids).map(async (j) => await j.scrape(options)));
console.log(JSON.stringify(metadata));
})
.parse(process.argv);