This repository has been archived by the owner on Jan 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorona.py
74 lines (70 loc) · 2.83 KB
/
corona.py
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
import sys
import bs4
import time
import datetime
from urllib import request
from urllib.request import Request
logo = '''\033[31m╔═╗┌─┐┬─┐┌─┐┌┐┌┌─┐┬ ┬┬┬─┐┬ ┬┌─┐
║ │ │├┬┘│ ││││├─┤└┐┌┘│├┬┘│ │└─┐
╚═╝└─┘┴└─└─┘┘└┘┴ ┴ └┘ ┴┴└─└─┘└─┘
\033[34m╔╦╗┬─┐┌─┐┌─┐┬┌─┌─┐┬─┐
║ ├┬┘├─┤│ ├┴┐├┤ ├┬┘
╩ ┴└─┴ ┴└─┘┴ ┴└─┘┴└─
\033[33m--------------------------------\033[0m'''
def Coronavirus(country):
''' Tracks the global coronavirus cases and deaths '''
# Global Cases
Head = {'User-Agent': 'Mozilla/5.0'}
URL = Request('https://www.worldometers.info/coronavirus/', headers=Head)
web = request.urlopen(URL).read().decode('utf8')
soup = bs4.BeautifulSoup(web, 'lxml')
title = soup.find('title').string
Gcases = title.split()[3]
Gdeaths = title.split()[6]
time = datetime.datetime.now().strftime('%d %B %Y @ %H:%M')
# Country Cases
URL = Request('https://www.worldometers.info/coronavirus/#countries', headers=Head)
web = request.urlopen(URL).read().decode('utf8')
soup = bs4.BeautifulSoup(web, 'lxml')
table = soup.find("table")
body = table.find('tbody')
rows = body.find_all('tr')
try:
country = country.title()
for row in rows:
cols = row.find_all('td')
cols = [ele.text.strip() for ele in cols]
if cols[0] == country:
if cols[2] == '': new = 0
else: new = cols[2]
if cols[1] == '': cases = 0
else: cases = cols[1]
if cols[3] == '': deaths = 0
else: deaths = cols[3]
if cols[6] == '': active = 0
else: active = cols[6]
if cols[5] == '': recovered = 0
else: recovered = cols[5]
out = '''{}\n Total Global Cases: \033[1;34m{}\033[0m\n Total Global Deaths: \033[31m{}\033[0m\n \033[1;36m{}:\033[0m\n Total Cases \033[1;34m{}\033[0m\n Total Deaths \033[31m{}\033[0m\n New Cases \033[35m{}\033[0m\n Still Active Cases \033[33m{}\033[0m\n Total Recovered \033[32m{}\033[0m\n----------'''\
.format(time, Gcases, Gdeaths, country, cases, deaths, new, active, recovered)
return((int(''.join(cases.split(','))), out))
except:
if country == '':
out = '''{}\n Total Global Cases: \033[1;34m{}\033[0m\n Total Global Deaths: \033[31m{}\033[0m\n----------'''\
.format(time, Gcases, Gdeaths)
return((int(''.join(Gcases.split(','))), out))
else:
out = 'No cases in {} or incorrect country name'.format(country)
print(out)
exit()
def main():
print(logo)
tick = 0
while True:
new, out = Coronavirus(' '.join(sys.argv[1:]))
if new > tick or new < tick:
tick = new
print(out)
else: pass
time.sleep(60)
if __name__ == '__main__': main()