-
Notifications
You must be signed in to change notification settings - Fork 0
/
covid.py
30 lines (26 loc) · 1.16 KB
/
covid.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
import requests
import xlrd
import pymongo
from pymongo import MongoClient
client = pymongo.MongoClient('mongodb+srv://rootUser:[email protected]/CovidData?retryWrites=true&w=majority')
db = client.get_database('CovidData')
covid_tests = db["countymodels"]
url = 'https://www.doh.wa.gov/Portals/1/Documents/1600/coronavirus/data-tables/PUBLIC_CDC_Event_Date_SARS.xlsx'
r = requests.get(url, allow_redirects=True)
workbook = xlrd.open_workbook(file_contents=r.content)
sheet = workbook.sheet_by_index(0)
counter = 1
info = str(sheet.cell(counter, 0).value.encode('ascii','ignore')).split()[0]
data = { 'name': info, 'weeks': [], 'cases': []}
while info != 'Unassigned':
week = sheet.cell(counter, 1).value
cases = sheet.cell(counter, 2).value
data["weeks"].append(str(week))
data["cases"].append(str(cases))
counter += 1
info = str(sheet.cell(counter, 0).value.encode('ascii','ignore')).split()[0]
if info != str(sheet.cell(counter - 1, 0).value.encode('ascii','ignore')).split()[0]:
covid_tests.replace_one({"name": data['name']}, data, True)
data['name'] = info
data['weeks'] = []
data['cases'] = []