Add country management to corona
This commit is contained in:
parent
cffeb9d0d0
commit
aeec641feb
2 changed files with 6 additions and 4 deletions
|
@ -59,6 +59,7 @@ LABEL=<span foreground='#a1d569'> </span>
|
|||
DISK=/run/media/flyingscorpio/Backup
|
||||
|
||||
[corona]
|
||||
COUNTRY=France
|
||||
interval=5
|
||||
|
||||
[crypto]
|
||||
|
|
|
@ -16,11 +16,11 @@ from typing import Any, Dict, List
|
|||
import matplotlib.pyplot as plt # type: ignore
|
||||
|
||||
|
||||
def grab_json_with_curl() -> str:
|
||||
def grab_json_with_curl(country: str) -> str:
|
||||
"""Run the curl command in a shell and grab the output as json."""
|
||||
|
||||
curl_cmd = subprocess.run(
|
||||
"curl -s 'https://corona-stats.online/France?source=1&format=json'",
|
||||
f"curl -s 'https://corona-stats.online/{country}?source=1&format=json'",
|
||||
capture_output=True,
|
||||
check=True,
|
||||
shell=True,
|
||||
|
@ -120,8 +120,9 @@ def main() -> None:
|
|||
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()
|
||||
country = os.environ.get("COUNTRY", default="France")
|
||||
print(f"Downloading data from {country} to corona file")
|
||||
curl_data = grab_json_with_curl(country)
|
||||
write_curl_to_file(curl_data, corona_file)
|
||||
|
||||
data = read_json_from_file(corona_file)
|
||||
|
|
Loading…
Add table
Reference in a new issue