add total count

master
Yiu Man Ho 2020-10-26 18:43:55 +08:00
commit 74159e1610
No known key found for this signature in database
GPG Key ID: 7939838BC85BF618
6 changed files with 117 additions and 0 deletions

60
main.py Normal file
View File

@ -0,0 +1,60 @@
from modules import emojiapp_config as ec
from modules import license as el
import os, csv, datetime, sys
import prettytable as pt
if len(sys.argv) == 1:
op = ""
else:
op = sys.argv[1]
if op == "license":
print(el.get())
exit()
app_name = "covid-19-check"
rdir = ec.get_root(app_name)
os.chdir(rdir)
if not os.path.isdir(rdir+"/COVID-19"):
status = os.system("git clone https://github.com/CSSEGISandData/COVID-19 --depth 1")
if not status == 0:
print("[Error] Can't clone the COVID-19 REPO")
exit(status)
os.chdir(rdir+"/COVID-19")
else:
os.chdir(rdir+"/COVID-19")
status = os.system("git pull")
if not status == 0:
print("[Error] Can't pull the COVID-19 REPO")
exit(status)
if op == "clone_only":
exit()
repo = rdir+"/COVID-19"
date = datetime.date.today() + datetime.timedelta(days=-1)
dstr = date.strftime('%m-%d-%Y')
csvdir = repo+"/csse_covid_19_data/csse_covid_19_daily_reports/"+dstr+".csv"
tc,td,tr,ta = 0,0,0,0
with open(csvdir, newline='') as csvfile:
rows = csv.reader(csvfile)
tb1 = pt.PrettyTable()
c = 0
for row in rows:
if c == 0:
tb1.field_names = row
c = 1
else:
if not op == "no_limit":
row[1] = (row[1][:10] + '..') if len(row[1]) > 10 else row[1]
row[2] = (row[2][:15] + '..') if len(row[2]) > 15 else row[2]
row[3] = (row[3][:15] + '..') if len(row[3]) > 15 else row[3]
row[11] = (row[11][:12] + '..') if len(row[11]) > 12 else row[11]
tb1.add_row(row)
tc = tc + int(row[7])
td = td + int(row[8])
tr = tr + int(row[9])
ta = ta + int(row[9])
tb1.align = "l"
print(tb1)
print("Total Confirmed: "+str(tc))
print("Total Death: "+str(td))
print("Total Recovered: "+str(tr))
print("Total Active: "+str(ta))

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,37 @@
import os , sys
from configparser import ConfigParser
from pathlib import Path
def get_root(name):
home = str(Path.home())
if not os.path.isdir(home+"/.emoji"):
print("[Warning] Data Dir not found, creating")
os.mkdir(home+"/.emoji")
if not os.path.isdir(home+"/.emoji/"+name):
print("[Warning] Data Sub Dir not found, creating")
os.mkdir(home+"/.emoji/"+name)
return home+"/.emoji/"+name
def get_config_dir(name):
rdir = get_root(name)
print("[Warning] Config File not found, creating")
if not os.path.isfile(name+"/config.conf"):
with open(name+"/config.conf", "w") as fp:
pass
return name+"/config.conf"
def get_config(name,section,item):
cfg = ConfigParser()
cdir = get_config_dir(name)
cfg.read(cdir)
return cfg.get(section,item)
def set_config(name,section,item,content):
cfg = ConfigParser()
cdir = get_config_dir(name)
cfg.read(cdir)
cfg.set(section,item,content)
with open(cdir, 'w') as configfile:
cfg.write(configfile)
cfg = ""

16
modules/license.py Normal file
View File

@ -0,0 +1,16 @@
def get():
return " Copyright 2020 Cato Yiu\n"\
"\n"\
" This program is free software: you can redistribute it and/or modify\n"\
" it under the terms of the GNU General Public License as published by\n"\
" the Free Software Foundation, either version 3 of the License, or\n"\
" (at your option) any later version.\n"\
"\n"\
" This program is distributed in the hope that it will be useful,\n"\
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"\
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"\
" GNU General Public License for more details\n"\
""\
" You should have received a copy of the GNU General Public License\n"\
" along with this program. If not, see <https://www.gnu.org/licenses/>."

4
plugins/__init__.py Normal file
View File

@ -0,0 +1,4 @@
from os.path import dirname, basename, isfile, join
import glob
modules = glob.glob(join(dirname(__file__), "*.py"))
__all__ = [ basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')]