Collection of Python scripts to download and display Covid-19 Data from the King County Public Health team.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

69 lines
2.4 KiB

#!/usr/bin/env python
"""
show_latest.py: Downloads and prints to stdout the latest daily
COVID-19 data from King County Washington from this site:
https://www.kingcounty.gov/depts/health/covid-19/data/daily-summary.aspx
"""
__author__ = "prasket"
from datetime import datetime
from openpyxl import load_workbook
import requests
import os
def download_data(save_location):
'''
We are downloading data in excel format from the King County
Public Health Department. No api is currently available for this
data, I have been in contact with King County Data team.
Here is a working url for example:
https://www.kingcounty.gov/depts/health/covid-19/data/~/media/depts/health/communicable-diseases/documents/C19/data/covid-data-extract-geography-august-10.xlsx
'''
# commenting out for now until data is updated, has been stale since 20200810
#dt_now = datetime.now()
#date = dt_now.strftime("%B" "-" "%d")
#url = "https://www.kingcounty.gov/depts/health/covid-19/data/~/media/depts/health/communicable-diseases/documents/C19/data/covid-data-extract-geography-" + date + ".xlsx"
url = "https://www.kingcounty.gov/depts/health/covid-19/data/~/media/depts/health/communicable-diseases/documents/C19/data/covid-data-extract-geography-august-10.xlsx"
if os.path.exists(save_location):
os.remove(save_location)
data = requests.get(url, allow_redirects=True)
open(save_location, 'wb').write(data.content)
return
def show_latest_data(zipcode, local_data):
wb = load_workbook(filename = local_data)
ws = wb['ZIP']
for row in ws.iter_rows(values_only=True):
if row[0] == "98121":
#zip = row[0]
population = row[1]
tests = row[2]
positives = row[4]
hospitalizations = row[6]
deaths = row[8]
print(">"*10,f"Current in {zipcode} Seattle, WA",">"*10)
print(f"Population = {population}")
print(f"Tests = {tests}")
print(f"Positives = {positives}")
print(f"Hospitilizations = {hospitalizations}")
print(f"Deaths = {deaths}")
print(">"*25,"<"*25)
return
def main():
zipcode = "98121"
local_data = "./covid-19_data.xlsx"
download_data(local_data)
show_latest_data(zipcode, local_data)
return
if __name__ == "__main__":
main()