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.
 
 
 

38 lines
1.0 KiB

#!/usr/bin/env python3
import os
import requests
def download():
url = "https://coronavirus.ohio.gov/static/dashboards/COVIDSummaryData.csv"
r = requests.get(url)
with open('COVIDdata.csv', 'wb') as f:
f.write(r.content)
print(r.status_code)
print(r.headers)
print(r.encoding)
def update():
with open('cases.csv', 'r') as cases:
latest = cases.readlines()[-1].strip('\n').split(',')
with open('COVIDdata.csv', 'r') as data:
govdata = data.readlines()[-1].strip('\n').replace(',','').split('"')
#this is so ugly
govdata = [ x for x in govdata if x ][-3:]
latest = [ int(i) for i in latest ]
govdata = [ int(i) for i in govdata ]
print(govdata)
if govdata[0] != latest[1]:
out = ""
out += str(latest[0] + 1) + ',' + str(govdata[0]) + ',' + str(govdata[1])
cmd = "echo {0} >> cases.csv".format(out.strip(','))
os.system(cmd)
print("new data added")
else:
print("up to date")
download()
update()