def update():
    '''PDFから感染者の情報を取得し,利用可能なjsonを書き出す
    '''

    # odfの情報取得
    pdf_data = get_data(setting)

    # サイトで使う用のデータを書き出す
    export_data(pdf_data)

    # pdfの全データをjsonとして書き出し
    row_data = []
    for data in pdf_data:
        temp_data = data
        if temp_data['revealed_dt'] is None:
            temp_data['revealed_dt'] = ''
        else:
            temp_data['revealed_dt'] = temp_data['revealed_dt'].strftime('%Y-%m-%d')
        if temp_data['appearance_dt'] is None:
            temp_data['appearance_dt'] = ''
        else:
            temp_data['appearance_dt'] = temp_data['appearance_dt'].strftime('%Y-%m-%d')
        row_data.append(temp_data)
    with open(os.path.dirname(os.path.abspath(__file__)) + "/data/row_data.json", "w") as f:
        json.dump(row_data, f, indent=4, ensure_ascii=False)
Ejemplo n.º 2
0
def generate_graphs():
    """Generates the graphs based on the countries from the user input"""
    # Grabs json data and User input
    json_data = get_data('https://covid2019-api.herokuapp.com/v2/current')
    # Generates list of all countries based on json data
    countries = [country['location'] for country in json_data]
    user_countries = take_user_data()
    # Iterates through user countries and raises an error if the user country does not exist
    for country in user_countries:
        if country not in countries:
            raise ValueError('Invalid country')
    # Generates a pygal bar graph object
    covid_graph = pygal.Bar()
    # Sets the x labels of the bar graph to this list
    covid_graph.x_labels = ['Confirmed Cases', 'Deaths', 'Recovered']
    # Iterates through the user_countries and adds country data to the bar graph
    for country in json_data:
        if country['location'] in user_countries:
            covid_graph.add(country['location'], [
                country['confirmed'], country['deaths'], country['recovered']
            ])
    covid_graph.render_to_file('covid_graph.svg')
    print('Graph generated as covid_graph.svg')
"""Grabs Coronavirus data and prints it in color to the terminal"""
# External Imports
from termcolor import colored
# Internal Imports
from get_covid_data import get_data

for item in get_data(f'https://covid2019-api.herokuapp.com/v2/current'):
    print(
        f"{colored(item['location'], 'yellow')} Confirmed: {colored(item['confirmed'], 'blue')},"
        f" Deaths: {colored(item['deaths'], 'red')}, Recovered: {colored(item['recovered'], 'green')}"
    )
Ejemplo n.º 4
0
import requests
import numpy as np
import matplotlib.pyplot as plt
from get_covid_data import get_data

json_ = get_data('https://covid2019-api.herokuapp.com/v2/current')

n_groups = len(json_)
location = [item['location'] for item in json_]
confirmed = [item['confirmed'] for item in json_]
deaths = [item['deaths'] for item in json_]
recovered = [item['recovered'] for item in json_]

fig, ax = plt.subplots()
index = np.arange(n_groups)
bar_width = 0.35
opacity = 0.8

rects1 = plt.bar(index, confirmed, bar_width,
alpha=opacity,
color='b',
label='confirmed')

rects3 = plt.bar(index + bar_width, recovered, bar_width,
alpha=opacity,
color='g',
label='recovered')

rects2 = plt.bar(index + bar_width, deaths, bar_width,
alpha=opacity,
color='r',