API to help make public data easier to access. Idea started with need for King County, WA COVID-19 data in API format while only having an excel file for source data.
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.
 
 

25 lines
858 B

import psycopg2
import csv
from datetime import datetime
conn = psycopg2.connect("host='localhost' dbname='apiv1' user='postgres' password='postgres'" )
cur = conn.cursor()
# take the source data csv and upload to the database.
# hardcoded to 20200810 right now
data_date = "20200810"
source_file = "covid-19_" +data_date+"_zip.csv"
with open(source_file, 'r') as f:
reader = csv.reader(f)
next(reader) # Skip the header row.
for row in reader:
cur.execute(
"INSERT INTO king_county_covid19_zip(date_data, zipcode, population, tests, test_rate, \
positives, positive_rate, hospitalizations, hospitalization_rate, deaths, death_rate) \
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
(data_date,row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9])
)
conn.commit()