Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding COVID Vacination data #30

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ fi
# run fetch
conda run -n c19-data python get_my_data.py dataset=states
conda run -n c19-data python tools/push_to_spreadsheet.py push.spreadsheet_id=1brHKBhqiXkkLyiDTDfaBK-tms-R4KVkI-NPFfFZwqYk push.sheet_id=0 push.file=outputs/states.csv creds.type=service creds.key_filepath=../creds/credentials.json
conda run -n c19-data python tools/push_to_spreadsheet.py push.spreadsheet_id=1brHKBhqiXkkLyiDTDfaBK-tms-R4KVkI-NPFfFZwqYk push.sheet_id=289169575 push.file=outputs/covid_vaccination_US.csv creds.type=service creds.key_filepath=../creds/credentials.json
2 changes: 2 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ dataset:
output: ${dataset.name}
data_root: ${hydra:runtime.cwd}/dataset/${dataset.name}
output_date_format: "%Y%m%d"
outputs: ${hydra:runtime.cwd}/outputs


# fetch a single state (or a list)
state: ['AK', 'AL', 'AR', 'AS', 'AZ', 'CA', 'CO', 'CT', 'DC', 'DE', 'FL', 'GA', 'GU',
Expand Down
16 changes: 15 additions & 1 deletion fetcher/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
import typing
import hydra
import pandas as pd
import os
import urllib.request

from fetcher.utils import Fields
from fetcher.source_utils import fetch_source, process_source_responses
from fetcher.sources import build_sources


# Indices
TS = 'TIMESTAMP'
STATE = Fields.STATE.name

site_url = "https://raw.githubusercontent.com/govex/COVID-19/master/data_tables/vaccine_data/raw_data" \
"/vaccine_data_us_state_timeline.csv "


class Fetcher:
def __init__(self, cfg):
Expand Down Expand Up @@ -170,6 +174,15 @@ def save_df_to_db(db_config, df):
df.to_sql(db_config.table, engine, if_exists='append', chunksize=200, method='multi')


def get_covid_vaccination_data(outputdir):
"""Download COVID Vaccination data in CSV format
"""
if os.path.exists(outputdir + '/' + 'covid_vaccination_US.csv'):
os.remove(outputdir + '/' + 'covid_vaccination_US.csv')

urllib.request.urlretrieve(site_url, os.path.join(outputdir, 'covid_vaccination_US.csv'))


@hydra.main(config_path='..', config_name="config")
def main(cfg):
print(cfg.dataset.pretty())
Expand All @@ -183,6 +196,7 @@ def main(cfg):
# This stores the CSV with the requsted fields in order
df = build_dataframe(results, cfg.state, cfg.dataset, cfg.output_date_format, cfg.output)
print(df)
get_covid_vaccination_data(cfg.outputs)

if 'db' in cfg.dataset and cfg.dataset.db.store:
save_df_to_db(cfg.dataset.db, df)