def countries(sort, limit): """Get Covid-19 data For All Countries.""" all_countries_table = PrettyTable() all_countries_table.field_names = [ color.prCyan('#'), color.prCyan('Country'), color.prCyan('Total Cases'), color.prCyan('Today Cases'), color.prRed('Total Deaths'), color.prRed('Today Deaths'), color.prGreen('Recovered Cases'), color.prYellow("Excluded cases"), color.prPurple("Critical") ] with yaspin(text="Civid-19 Cases Of All Continents", color="cyan") as sp: for country in get_countries.all_countries(sort, limit): all_countries_table.add_row(country) all_countries_table.align = 'r' all_countries_table.align[color.prCyan('Continent')] = 'l' click.echo(all_countries_table) print(sort)
def crash_msg(error_code, file: str, fixes: str): pecho( color.prCyan(":(") ) pecho(color.prRed("There was an error which forced Coronapy to crash") ) pecho(color.prGreen("But you can report this bug! https://github.com/MouadBH/coronapy-cli/issues") ) pecho(color.prPurple("Before you report the bug, please try these fixes: " + fixes) ) pecho(color.prRed("ERROR Code: \n" + str(error_code) + "in file " + file + "\n You can put this error code in the bug report (it would help us out)") ) exit()
def country(country, chart, hist, type): """Get data of a specific country.""" worldwide_table = PrettyTable() worldwide_table.field_names = [ color.prCyan('Country'), color.prCyan('Total Cases'), color.prCyan('Today Cases'), color.prRed('Total Deaths'), color.prRed('Today Deaths'), color.prGreen('Recovered Cases'), color.prYellow("Excluded cases"), color.prPurple("Critical") ] with yaspin(text="Civid-19 Cases Of " + country, color="cyan") as sp: data, meta_data = get_country.get_country(country) cnt_name = data[0] cnt_value = [f'{i:,}' for i in data[1:]] cnt_data = [] cnt_data.append(cnt_name) for x in cnt_value: cnt_data.append(x) worldwide_table.add_row(cnt_data) time.sleep(1) click.echo(worldwide_table) print(' ') if chart: labels = ['Total Cases', 'Total Deaths', 'Recovered Cases'] data_chart = [data[1], data[3], data[5]] data_chart = [[int(i)] for i in data_chart] args = {'stacked': False, 'width': 100, 'no_labels': False, 'format': '{:,}', 'suffix': '', "vertical": False} tg.chart(colors=[91, 94], data=data_chart, args=args, labels=labels) if hist: country_full_name = data[0] with yaspin(text="Drawing a histogram of " + country, color="cyan") as sp: try: labels_hist, hist_data = get_country.get_country_hist(country_full_name, type) except KeyError as err: click.secho("\n" + str(err), bg='black', fg='red', bold=True) return time.sleep(1) args = {'stacked': False, 'width': 100, 'no_labels': False, 'format': '{:,}', 'suffix': '', "vertical": False} click.secho("COVID-19 '" + type + "' for last 20 day in " + country_full_name + ".", bg='black', fg='yellow', blink=True, bold=True) try: tg.chart(colors=[91, 94], data=hist_data, args=args, labels=labels_hist) except IndexError: click.secho("No historical data found in " + country + ".", bg='black', fg='red', bold=True)
def init(): click.clear() f = Figlet(font='slant') click.echo( str(color.prCyan(f.renderText('Corona CLI'))) + str(color.prGreen('Corona-cli')) + str(color.prYellow('v1.3.9')) + ' by MouadBH.') click.echo( str( color.prPurple( 'Follow me on Twitch: https://www.twitch.tv/chibakutsy'))) click.echo(str(color.prRed('Track the Coronavirus disease (COVID-19).'))) print(' \n')
def country(country, chart, hist, type): """Get data of a specific country.""" worldwide_table = PrettyTable() worldwide_table.field_names = [ color.prCyan('Country'), color.prCyan('Total Cases'), color.prCyan('Today Cases'), color.prRed('Total Deaths'), color.prRed('Today Deaths'), color.prGreen('Recovered Cases'), color.prYellow("Excluded cases"), color.prPurple("Critical") ] with yaspin(text="Civid-19 Cases Of " + country, color="cyan") as sp: data, meta_data = get_country.get_country(country) worldwide_table.add_row(data) time.sleep(1) click.echo(worldwide_table) print(' ') if chart: labels = ['Total Cases', 'Total Deaths', 'Recovered Cases'] data_chart = [data[1], data[3], data[5]] data_chart = [[int(i)] for i in data_chart] args = { 'stacked': False, 'width': 100, 'no_labels': False, 'format': '{:,}', 'suffix': '', "vertical": False } tg.chart(colors=[91, 94], data=data_chart, args=args, labels=labels) if hist: with yaspin(text="Drawing a histogram of " + country, color="cyan") as sp: # Handle ISO-code as country name by using country name from meta-info of countries endpoint labels_hist, hist_data = get_country.get_country_hist( meta_data['country'], type) time.sleep(1) args = { 'stacked': False, 'width': 100, 'no_labels': False, 'format': '{:,}', 'suffix': '', "vertical": False } click.secho("Civid-19 '" + type + "' for last 20 day in " + meta_data['country'] + ".", bg='black', fg='yellow', blink=True, bold=True) try: tg.chart(colors=[91, 94], data=hist_data, args=args, labels=labels_hist) except IndexError: click.secho("No historical data found in " + country + ".", bg='black', fg='red', bold=True)