Skip to content

Instantly share code, notes, and snippets.

@X-88
Created April 11, 2020 01:01
Show Gist options
  • Save X-88/ae1b85262c8bdcbe5a61dd3a717f3a83 to your computer and use it in GitHub Desktop.
Save X-88/ae1b85262c8bdcbe5a61dd3a717f3a83 to your computer and use it in GitHub Desktop.
Update Information About Covid-19/NCoV-19
#library units
from datetime import datetime
import urllib.request
import json
import ssl
import os
#date
dt = datetime.today().strftime('%m/%d/%Y')
#text color
cl1 = '\033[1;36m'
cl2 = '\033[1;33m'
cl3 = '\033[1;31m'
cl4 = '\033[1;32m'
cl5 = '\033[1;37m'
ecl = '\033[0m'
def getdata():
#clear screen
os.system('clear')
#separator
spr = cl1 + '===============================' + ecl
print(spr + cl5 + '\nUpdate Covid-19 Pandemic\nCoded by: Zephio/X-88\nLanguage: Python 3xx\n' + ecl + spr)
#http get
country = input(cl4 + 'Enter Your Country: ' + ecl)
#data source
url = 'https://coronavirus-19-api.herokuapp.com/countries/'+str(country)
#user agent
headers = {}
headers['User-Agent'] = "Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127Firefox/2.0.0.11"
#ssl
ssl._create_default_https_context = ssl._create_unverified_context
#http get
req = urllib.request.Request(url, headers=headers)
html = urllib.request.urlopen(req).read().decode('utf-8')
#load json
data = json.loads(html)
c = data['cases']
d = data['deaths']
r = data['recovered']
a = data['active']
x = ((d / c) * 100)
y = ((r / c) * 100)
z = ((a / c) * 100)
print(spr + cl2 + '\nCountry:', data['country'],
'\nCases:', data['cases'],
'\nDeaths:', data['deaths'], '(' + str(round(x)) + '%)',
'\nRecovered:', data['recovered'], '(' + str(round(y)) + '%)',
'\nActive:', data['active'], '(' + str(round(z)) + '%)',
'\nTotal Tests:', data['totalTests'],
'\nToday Cases:', data['todayCases'],
'\nToday Deaths:', data['todayDeaths'],
'\nCritical:', data['critical'])
print('Date:', dt, ecl)
os.system('sleep 1')
inp = input(spr + cl3 + '\nPress [Enter] to Return\n' + ecl + spr + cl3 + '\n>>>' + ecl)
if True:
os.system('clear')
return getdata()
getdata()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment