11/* eslint-disable no-await-in-loop */
22
33const style = require ( 'ansi-styles' ) ,
4- request = require ( "request" ) ,
54 fs = require ( 'fs' ) ,
65 table3 = require ( 'cli-table3' ) ;
76
7+ const axios = require ( 'axios' ) ;
8+
89const tblopn = style . cyan . open ,
910 tblcls = style . cyan . close ;
1011
12+ const apiBaseURL = "https://corona.lmao.ninja" ;
13+
1114// package.json information
1215const pkg = JSON . parse ( fs . readFileSync ( 'package.json' ) ) ;
1316
@@ -24,20 +27,9 @@ let ts = Date.now(),
2427 year = date_ob . getFullYear ( ) ,
2528 currentdate = month + "/" + date + "/" + year ;
2629
27- // api request for global data
28- request . get ( "https://corona.lmao.ninja/all" , ( error , response , body ) => {
29- if ( error ) {
30- return console . dir ( error ) ;
31- }
32- globalData = JSON . parse ( body ) ;
33- } ) ;
34-
3530// covid19 global tracker
36- exports . covid19globaltracker = ( ) => {
37- const cases = globalData . cases ,
38- deaths = globalData . deaths ,
39- recovered = globalData . recovered ,
40- asof = new Date ( globalData . updated ) ,
31+ exports . covid19globaltracker = ( c , d , r , u ) => {
32+ const cases = c , deaths = d , recovered = r , asof = new Date ( u ) ,
4133 table = new table3 ( {
4234 head : [ { colSpan :3 , content :`${ style . white . open } COVID-19 Tracker CLI v` + pkg . version + ` - Global Update${ style . white . close } ` } ] ,
4335 chars : { 'top' : `${ tblopn } ═${ tblcls } ` ,
@@ -67,12 +59,56 @@ exports.covid19globaltracker = () => {
6759 return table . toString ( ) + '\n' + footer ;
6860} ;
6961
62+ const lastupdate = async ( ) => {
63+ return await axios . get ( `${ apiBaseURL } /all` ) . then ( function ( res ) {
64+ const update = res . data . updated ;
65+ return update . toLocaleString ( ) ;
66+ } ) ;
67+ } ;
68+
69+ exports . covid19countrytracker = ( n , c , tC , d , tD , r , a , cl , cPOM , u ) => {
70+ const name = n , cases = c , todayCases = tC ,
71+ deaths = d , todayDeaths = tD , recovered = r ,
72+ active = a , critical = cl , casesPerOneMillion = cPOM ,
73+ asof = new Date ( u ) ;
74+ table = new table3 ( {
75+ head : [ { colSpan :4 , content :`${ style . white . open } COVID-19 Tracker CLI v` + pkg . version + ` - ${ name } Update${ style . white . close } ` } ] ,
76+ chars : { 'top' : `${ tblopn } ═${ tblcls } ` ,
77+ 'top-mid' : `${ tblopn } ╤${ tblcls } ` ,
78+ 'top-left' : `${ tblopn } ╔${ tblcls } ` ,
79+ 'top-right' : `${ tblopn } ╗${ tblcls } ` ,
80+ 'bottom' : `${ tblopn } ═${ tblcls } ` ,
81+ 'bottom-mid' : `${ tblopn } ╧${ tblcls } ` ,
82+ 'bottom-left' : `${ tblopn } ╚${ tblcls } ` ,
83+ 'bottom-right' : `${ tblopn } ╝${ tblcls } ` ,
84+ 'left' : `${ tblopn } ║${ tblcls } ` ,
85+ 'left-mid' : `${ tblopn } ╟${ tblcls } ` ,
86+ 'mid' : `${ tblopn } ─${ tblcls } ` ,
87+ 'mid-mid' : `${ tblopn } ┼${ tblcls } ` ,
88+ 'right' : `${ tblopn } ║${ tblcls } ` ,
89+ 'right-mid' : `${ tblopn } ╢${ tblcls } ` ,
90+ 'middle' : `${ tblopn } │${ tblcls } ` }
91+ } ) ;
92+
93+ table . push (
94+ [ { colSpan :4 , content :style . gray . open + 'As of ' + asof . toLocaleString ( ) + ' [Date:' + currentdate + ']' + style . gray . close } ] ,
95+ [ `${ style . magenta . open } Cases${ style . magenta . close } ` , `${ style . red . open } Deaths${ style . red . close } ` , `${ style . green . open } Recovered${ style . green . close } ` , `${ style . cyan . open } Active${ style . cyan . close } ` ] ,
96+ [ formatNumber ( cases ) , formatNumber ( deaths ) , formatNumber ( recovered ) , formatNumber ( active ) ] ,
97+ [ `${ style . magentaBright . open } Today Cases${ style . magentaBright . close } ` , `${ style . redBright . open } Today Deaths${ style . red . close } ` , `${ style . redBright . open } Critical${ style . redBright . close } ` , `${ style . cyanBright . open } Cases Per Million${ style . cyanBright . close } ` ] ,
98+ [ formatNumber ( todayCases ) , formatNumber ( todayDeaths ) , formatNumber ( critical ) , formatNumber ( casesPerOneMillion ) ] ,
99+ [ { colSpan :4 , content :style . gray . open + `Source: https://www.worldometers.info/coronavirus/` + style . gray . close } ] ,
100+ [ { colSpan :4 , content :style . gray . open + `Code: https://github.com/warengonzaga/covid19-tracker-cli` + style . gray . close } ]
101+ ) ;
102+
103+ return table . toString ( ) + '\n' + footer ;
104+ } ;
105+
70106const footer = `
71107 Always wash your hands, stay safe...
72108
73109 ---
74110 Love this project? Please consider buying me a cup of coffee!
75- ${ style . yellow . open } buymeacoff.ee/warengonzaga ${ style . yellow . close }
111+ ${ style . yellow . open } warengonzaga.com/buymeacoffee ${ style . yellow . close }
76112
77113 ---
78114 Follow ${ style . bgCyan . open } ${ style . black . open } @warengonzaga${ style . black . close } ${ style . bgCyan . close } for more updates!
0 commit comments