-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_convid_tn.py
46 lines (35 loc) · 1.15 KB
/
get_convid_tn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import requests
from datetime import datetime
r = requests.get("https://www.tn.gov/health/cedep/ncov.html")
marker = '<p>Patient county name</p>'
if marker not in r.text:
marker = '<p>County</p>'
if marker not in r.text:
marker = "<b>County</b>"
if marker not in r.text:
marker = "positives"
body = r.text[r.text.find(marker):]
body = body.split("<tr")
total = 0
f = open('convid_tn.csv', "a")
for line in body:
if "<th>" in line or "<tbody>" in line or "</th>" in line:
continue
if "</tbody>" in line:
break
cell = line.split("<td")
county = cell[1][cell[1].find("<p>")+3:cell[1].find("</p>")]
num = cell[2][cell[2].find("<p>")+3:cell[2].find("</p>")]
timestampStr = datetime.now().strftime("%d-%b-%Y (%H:%M:%S.%f)")
try:
num = num.replace("<b>", "")
num = num.replace("</b>", "")
total += int(num)
except:
# We just display this - who cares if it fails
print("Error converging {0} to int".format(num))
output = '"{0}", "{1}", {2}\n'.format(timestampStr, county, num)
print(output)
f.write(output)
print(total)
f.close()