-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·64 lines (48 loc) · 1.42 KB
/
index.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env node
const Table = require('cli-table3'),
figlet = require('figlet'),
chalk = require('chalk'),
clear = require('clear'),
fetch = require('node-fetch'),
minimist = require('minimist'),
argv = minimist(process.argv.splice(2)),
refresh = argv.refresh || false,
shouldClear = argv.clear || !!refresh;
async function getData() {
const url = 'https://wrapapi.com/use/mluedke/covid-19/ny/latest?wrapAPIKey=9DWU2AcN3XbVvgKIJDOugyD0hnBOlPtf';
return fetch(url).then(async (resp) => {
const body = await resp.json();
return body.data;
});
}
async function drawData(data) {
// Clear the old output
if (shouldClear) {
clear();
}
// Write header
console.log(
chalk.blueBright(
figlet.textSync('NY COVID 19', { horizontalLayout: 'full' })
)
)
console.log(chalk.redBright(`Total Cases: ${data.totalCases}`))
// blank line
console.log('');
console.log('BY COUNTY')
// full screen dashed line
console.log(new Array(process.stdout.columns + 1).join('-'));
const table = new Table({ head: ['County', 'Cases'] });
data.byCounty.forEach((county) => {
table.push([ county.name, county.count ]);
});
console.log(table.toString());
}
function run() {
getData().then(drawData);
if (refresh) {
// refresh is set in hours
setTimeout(run, refresh * 3600 * 1000);
}
}
run();