forked from OSSPhilippines/covid19-tracker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
81 lines (74 loc) · 3 KB
/
Copy pathindex.js
File metadata and controls
81 lines (74 loc) · 3 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const
blessed = require('blessed'),
pkg = require('../../../package.json'),
say = require('../../sayings/threads.json'),
serverUtil = require('./server-util')
template = require ('./template.js'),
{sm, md, lg} = require('../../../bin/util/layout'),
ts = Date.now(),
date_ob = new Date(ts),
date = date_ob.getDate(),
month = date_ob.getMonth() + 1,
year = date_ob.getFullYear(),
currentdate = month + "/" + date + "/" + year,
space = ' ',
br = '\n',
header = '`COVID19-TRACKER-CLI (v'+pkg.version+')`',
tagline = '*A curl-based command line tracker for Novel Coronavirus or COVID-19 pandemic.*',
source = 'Source: https://www.worldometers.info/coronavirus/',
repo = 'Code: https://github.com/warengonzaga/covid19-tracker-cli',
bmcurl = 'warengonza.ga/coffee4dev',
twitterhandle = '@warengonzaga',
twitterhashtag = '#covid19trackercli',
gcashNum = '+639176462753',
ansiBMC = '`(Buy Me A Coffee)` '+bmcurl,
ansiTwitter = twitterhandle+space+twitterhashtag,
ansiGCash = '(GCash) '+gcashNum;
const randomSay = () => {
let random = Math.floor(Math.random() * say.length);
return say[random];
};
const patchBlessed = () => {
blessed.Program.prototype.listem = function() {}
process.on = function() {}
};
patchBlessed();
exports.historyCountryTracker = (req, res, n, c, tC, d, tD, r, a, cl, cPOM, u, h, chartType, countryInfo, chartSize = 'sm') => {
const name = n, cases = c, todayCases = tC,
deaths = d, todayDeaths = tD, recovered = r,
active = a, critical = cl, casesPerOneMillion = cPOM,
mortalityPercentage = (d/c)*100, recoveredPercentage = (r/c)*100,
asof = new Date(u),
dates = Object.keys(h.timeline[chartType]),
from = dates[0],
to = dates[dates.length - 1],
tableFooter = randomSay(),
defaultfooter = ansiBMC+ansiTwitter+br+br,
specialfooter = ansiGCash+br+ansiBMC+ansiTwitter+br+br,
defaultHeader = header+br+tagline,
footer = (n.toLowerCase() == 'philippines') ? tableFooter+br+specialfooter+br+source+br+repo : tableFooter+br+defaultfooter+br+source+br+repo,
defaultChartStyle = chartSize === 'sm' ? sm : (chartSize === 'md' ? md : lg);
serverUtil.loadTemplate(template, defaultChartStyle, {
name,
cases,
deaths,
recovered,
active,
casesPerOneMillion,
todayCases,
todayDeaths,
critical,
mortalityPercentage,
recoveredPercentage,
countryInfo,
from,
to,
currentdate,
asof,
h,
defaultHeader,
footer,
}, (screen) => {
res.send(screen+'\r\n'+'\033[?25h')
})
};