forked from covidatlas/coronadatascraper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
30 lines (23 loc) · 781 Bytes
/
cli.js
File metadata and controls
30 lines (23 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import path from 'path';
import yargs from 'yargs';
import generate from './index.js';
import * as fs from './lib/fs.js';
import * as stringify from './lib/stringify.js';
const argv = yargs
.option('date', {
alias: 'd',
description: 'Generate data for the provided date in YYYY-M-D format',
type: 'string',
})
.help()
.alias('help', 'h')
.argv;
async function writeData({ locations }) {
let date = process.env['SCRAPE_DATE'] ? '-' + process.env['SCRAPE_DATE'] : '';
await fs.ensureDir('dist')
await fs.writeFile(path.join('dist', `data${date}.json`), JSON.stringify(locations, null, 2));
await fs.writeCSV(path.join('dist', `data${date}.csv`), stringify.csvForDay(locations));
return { locations };
}
generate(argv.date)
.then(writeData);