-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (46 loc) · 1.25 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
const graphqlGot = require('graphql-got');
const omegaOled = require('onion-omega-oled');
// The region from which you want to display stats
const region = 'Poland';
const query = `{
locations {
region
confirmed
recovered
deaths
}
}`;
const fetchAndDisplay = async () => {
try {
let stats = {
confirmed: undefined,
recovered: undefined,
deaths: undefined
};
const response = await graphqlGot('https://coronavirusapi.me/', {query});
const data = response.body.locations.filter(object => object.region === region);
// eslint-disable-next-line array-callback-return
await data.map(element => {
stats = {
confirmed: element.confirmed,
recovered: element.recovered,
deaths: element.deaths
};
});
omegaOled.init().then(() => {
omegaOled.chainMode(true);
omegaOled.write(`Status for ${region}:`);
omegaOled.cursor(2, 0);
omegaOled.write(`Confirmed: ${stats.confirmed}`);
omegaOled.cursor(3, 0);
omegaOled.write(`Recovered: ${stats.recovered}`);
omegaOled.cursor(4, 0);
omegaOled.write(`Deaths: ${stats.deaths}`);
omegaOled.executeChain();
});
} catch (error) {
console.log(error.response.body);
}
};
fetchAndDisplay();
setInterval(fetchAndDisplay, 3600000);