Add dates to graph

This commit is contained in:
flyingscorpio@arch-desktop 2020-05-06 12:45:59 +02:00
parent af5fc9c48c
commit 45ee07ea88

View file

@ -5,7 +5,7 @@
Author: flyingscorpio Author: flyingscorpio
""" """
from datetime import datetime from datetime import datetime, timedelta
import json import json
import locale import locale
import os import os
@ -87,18 +87,21 @@ def print_to_output(confirmed: int, today_confirmed_int: int,
def generate_graph(data: List[int]) -> None: def generate_graph(data: List[int]) -> None:
"""Generate a small graph based on the evolution of numbers in the list.""" """Generate a small graph based on the evolution of numbers in the list."""
X = range(len(data)) plt.plot(
plt.plot(X, [data[i] for i in X]) [
datetime.today().date() - timedelta(days=i)
for i in reversed(range(len(data)))
],
data
)
plt.show() plt.show()
def main() -> None: def is_up_to_date(path: Path) -> bool:
"""Grab the data, select the region, split the values.""" """Stat the downloaded file and return if it is up to date."""
corona_file = Path("~/.cache/corona").expanduser()
stat_cmd = subprocess.run( stat_cmd = subprocess.run(
f"stat -c %y {corona_file} | cut -d' ' -f1", f"stat -c %y {path} | cut -d' ' -f1",
capture_output=True, capture_output=True,
check=False, check=False,
shell=True, shell=True,
@ -108,9 +111,16 @@ def main() -> None:
current_date = datetime.now() current_date = datetime.now()
today = f"{current_date.year}-{current_date.month:02d}-{current_date.day:02d}" today = f"{current_date.year}-{current_date.month:02d}-{current_date.day:02d}"
if stat_date == today: return stat_date == today
data = read_json_from_file(corona_file)
else:
def main() -> None:
"""Grab the data, select the region, split the values."""
corona_file = Path("~/.cache/corona").expanduser()
if not is_up_to_date(corona_file):
print("Downloading data to corona file")
curl_data = grab_json_with_curl() curl_data = grab_json_with_curl()
write_curl_to_file(curl_data, corona_file) write_curl_to_file(curl_data, corona_file)