Skip to content

Instantly share code, notes, and snippets.

@walice
Created August 12, 2025 21:09
Show Gist options
  • Select an option

  • Save walice/02db83dca30fcb08af489db560739b6a to your computer and use it in GitHub Desktop.

Select an option

Save walice/02db83dca30fcb08af489db560739b6a to your computer and use it in GitHub Desktop.
Jupyter notebook used in a project combining notebook automation with web deployment to create self-maintaining data dashboards. Full tutorial available at: https://alicelepissier.com/programming/automated-notebook.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"papermill": {
"duration": 0.011892,
"end_time": "2020-08-28T03:33:59.527772",
"exception": false,
"start_time": "2020-08-28T03:33:59.515880",
"status": "completed"
},
"tags": []
},
"source": [
"# Daily COVID monitoring data for Santa Barbara county"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2020-08-28T03:33:59.555636Z",
"iopub.status.busy": "2020-08-28T03:33:59.555135Z",
"iopub.status.idle": "2020-08-28T03:34:01.141778Z",
"shell.execute_reply": "2020-08-28T03:34:01.142744Z"
},
"papermill": {
"duration": 1.60479,
"end_time": "2020-08-28T03:34:01.142959",
"exception": false,
"start_time": "2020-08-28T03:33:59.538169",
"status": "completed"
},
"tags": [
"remove_cell"
]
},
"outputs": [],
"source": [
"! jt -t grade3 -tf robotosans -cellw 1100"
]
},
{
"cell_type": "markdown",
"metadata": {
"papermill": {
"duration": 0.009502,
"end_time": "2020-08-28T03:34:01.162898",
"exception": false,
"start_time": "2020-08-28T03:34:01.153396",
"status": "completed"
},
"tags": []
},
"source": [
"This table is automatically updated with new daily COVID data for the county of Santa Barbara, CA. Every day, the California Department of Public Health publishes COVID tracking metrics for each county, but does not save the previous day's data. This tool keeps track of the daily metrics that are used to monitor progress towards safe reopening in California."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"execution": {
"iopub.execute_input": "2020-08-28T03:34:01.190502Z",
"iopub.status.busy": "2020-08-28T03:34:01.187036Z",
"iopub.status.idle": "2020-08-28T03:34:03.885171Z",
"shell.execute_reply": "2020-08-28T03:34:03.885993Z"
},
"papermill": {
"duration": 2.713436,
"end_time": "2020-08-28T03:34:03.886203",
"exception": false,
"start_time": "2020-08-28T03:34:01.172767",
"status": "completed"
},
"slideshow": {
"slide_type": "skip"
},
"tags": [
"remove_cell"
]
},
"outputs": [],
"source": [
"# Preamble\n",
"import os\n",
"from IPython.display import Markdown as md\n",
"import IPython\n",
"import requests\n",
"from bs4 import BeautifulSoup\n",
"import re\n",
"import pandas as pd\n",
"import datetime\n",
"import gspread\n",
"from oauth2client.service_account import ServiceAccountCredentials"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"execution": {
"iopub.execute_input": "2020-08-28T03:34:03.912382Z",
"iopub.status.busy": "2020-08-28T03:34:03.911784Z",
"iopub.status.idle": "2020-08-28T03:34:03.913180Z",
"shell.execute_reply": "2020-08-28T03:34:03.912784Z"
},
"papermill": {
"duration": 0.01661,
"end_time": "2020-08-28T03:34:03.913297",
"exception": false,
"start_time": "2020-08-28T03:34:03.896687",
"status": "completed"
},
"tags": [
"remove_cell"
]
},
"outputs": [],
"source": [
"# Set working directory\n",
"os.chdir(\"/home/alice_lepissier/COVID-SB\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"execution": {
"iopub.execute_input": "2020-08-28T03:34:03.939057Z",
"iopub.status.busy": "2020-08-28T03:34:03.938527Z",
"iopub.status.idle": "2020-08-28T03:34:05.340871Z",
"shell.execute_reply": "2020-08-28T03:34:05.341720Z"
},
"papermill": {
"duration": 1.419126,
"end_time": "2020-08-28T03:34:05.341902",
"exception": false,
"start_time": "2020-08-28T03:34:03.922776",
"status": "completed"
},
"slideshow": {
"slide_type": "skip"
},
"tags": [
"remove_cell"
]
},
"outputs": [],
"source": [
"# Request content from URL\n",
"html_string = requests.get('https://www.cdph.ca.gov/Programs/CID/DCDC/Pages/COVID-19/COVID19CountyDataTable.aspx').content"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"execution": {
"iopub.execute_input": "2020-08-28T03:34:05.371674Z",
"iopub.status.busy": "2020-08-28T03:34:05.371090Z",
"iopub.status.idle": "2020-08-28T03:34:05.473224Z",
"shell.execute_reply": "2020-08-28T03:34:05.474033Z"
},
"papermill": {
"duration": 0.121712,
"end_time": "2020-08-28T03:34:05.474225",
"exception": false,
"start_time": "2020-08-28T03:34:05.352513",
"status": "completed"
},
"slideshow": {
"slide_type": "skip"
},
"tags": [
"remove_cell"
]
},
"outputs": [],
"source": [
"# Parse HTML\n",
"soup = BeautifulSoup(html_string, 'html.parser')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"execution": {
"iopub.execute_input": "2020-08-28T03:34:05.504868Z",
"iopub.status.busy": "2020-08-28T03:34:05.504365Z",
"iopub.status.idle": "2020-08-28T03:34:05.510967Z",
"shell.execute_reply": "2020-08-28T03:34:05.511859Z"
},
"papermill": {
"duration": 0.027491,
"end_time": "2020-08-28T03:34:05.512040",
"exception": false,
"start_time": "2020-08-28T03:34:05.484549",
"status": "completed"
},
"slideshow": {
"slide_type": "skip"
},
"tags": [
"remove_cell"
]
},
"outputs": [],
"source": [
"# Extract data for Santa Barbara\n",
"table = soup.find_all(\"tr\", class_=\"ms-rteTableEvenRow-3\")\n",
"SB = table[21]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"execution": {
"iopub.execute_input": "2020-08-28T03:34:05.540802Z",
"iopub.status.busy": "2020-08-28T03:34:05.540293Z",
"iopub.status.idle": "2020-08-28T03:34:05.552576Z",
"shell.execute_reply": "2020-08-28T03:34:05.553453Z"
},
"papermill": {
"duration": 0.031302,
"end_time": "2020-08-28T03:34:05.553622",
"exception": false,
"start_time": "2020-08-28T03:34:05.522320",
"status": "completed"
},
"slideshow": {
"slide_type": "skip"
},
"tags": [
"remove_cell"
]
},
"outputs": [],
"source": [
"# Avg # tests per day (per 100,000 population)\n",
"daily_tests = SB.find_all(\"td\", class_=\"ms-rteTableOddCol-3\")[0].text\n",
"\n",
"# Case rate per 100,000\n",
"case_rate = SB.find_all(\"td\", class_=\"ms-rteTableEvenCol-3\")[1].text\n",
"\n",
"# Testing positivity (%)\n",
"test_positivity = SB.find_all(\"td\", class_=\"ms-rteTableOddCol-3\")[1].text\n",
"\n",
"# % Change in 3-day avg COVID+ hospitalized patients\n",
"change_hospit = SB.find_all(\"td\", class_=\"ms-rteTableEvenCol-3\")[2].text\n",
"\n",
"# % ICU beds currently available\n",
"ICU_beds = SB.find_all(\"td\", class_=\"ms-rteTableOddCol-3\")[2].text\n",
"\n",
"# % Ventilators currently available\n",
"ventilators = SB.find_all(\"td\", class_=\"ms-rteTableEvenCol-3\")[3].text\n",
"\n",
"# Extract date of last update\n",
"update_date = soup.find_all(\"span\", class_=\"ms-rteStyle-Accent1\")[1]\\\n",
" .find(\"em\").text"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"execution": {
"iopub.execute_input": "2020-08-28T03:34:05.581331Z",
"iopub.status.busy": "2020-08-28T03:34:05.580634Z",
"iopub.status.idle": "2020-08-28T03:34:05.582180Z",
"shell.execute_reply": "2020-08-28T03:34:05.581757Z"
},
"papermill": {
"duration": 0.017387,
"end_time": "2020-08-28T03:34:05.582300",
"exception": false,
"start_time": "2020-08-28T03:34:05.564913",
"status": "completed"
},
"tags": [
"remove_cell"
]
},
"outputs": [],
"source": [
"# Create updated date string\n",
"update_tag = \"Table last updated by CDPH on \" + update_date.split(\" on \", 1)[1] + \".\""
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"execution": {
"iopub.execute_input": "2020-08-28T03:34:05.605843Z",
"iopub.status.busy": "2020-08-28T03:34:05.605336Z",
"iopub.status.idle": "2020-08-28T03:34:05.623202Z",
"shell.execute_reply": "2020-08-28T03:34:05.624025Z"
},
"papermill": {
"duration": 0.032072,
"end_time": "2020-08-28T03:34:05.624189",
"exception": false,
"start_time": "2020-08-28T03:34:05.592117",
"status": "completed"
},
"slideshow": {
"slide_type": "skip"
},
"tags": [
"remove_cell"
]
},
"outputs": [],
"source": [
"# Set up Google Sheet API\n",
"scope = [\"https://spreadsheets.google.com/feeds\",'https://www.googleapis.com/auth/spreadsheets',\"https://www.googleapis.com/auth/drive.file\",\"https://www.googleapis.com/auth/drive\"]\n",
"creds = ServiceAccountCredentials.from_json_keyfile_name(\"credentials.json\", scope)\n",
"client = gspread.authorize(creds)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"execution": {
"iopub.execute_input": "2020-08-28T03:34:05.651604Z",
"iopub.status.busy": "2020-08-28T03:34:05.651008Z",
"iopub.status.idle": "2020-08-28T03:34:06.802898Z",
"shell.execute_reply": "2020-08-28T03:34:06.803625Z"
},
"papermill": {
"duration": 1.16925,
"end_time": "2020-08-28T03:34:06.803788",
"exception": false,
"start_time": "2020-08-28T03:34:05.634538",
"status": "completed"
},
"slideshow": {
"slide_type": "skip"
},
"tags": [
"remove_cell"
]
},
"outputs": [
{
"data": {
"text/plain": [
"{'spreadsheetId': '13GG0FPUFg_5xCouN0ZF3woaPXwjuxL2Dw3uYIfwUW-Q',\n",
" 'updatedRange': 'Sheet1!A2:G2',\n",
" 'updatedRows': 1,\n",
" 'updatedColumns': 7,\n",
" 'updatedCells': 7}"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Append daily data as a new row in Google Sheet\n",
"sheet = client.open(\"COVID Daily Metrics\").sheet1\n",
"insertRow = [datetime.date.today().strftime(\"%Y-%m-%d\"),\n",
" daily_tests,\n",
" case_rate,\n",
" test_positivity,\n",
" change_hospit,\n",
" ICU_beds,\n",
" ventilators]\n",
"sheet.insert_row(insertRow, 2)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"execution": {
"iopub.execute_input": "2020-08-28T03:34:06.834486Z",
"iopub.status.busy": "2020-08-28T03:34:06.833965Z",
"iopub.status.idle": "2020-08-28T03:34:07.576054Z",
"shell.execute_reply": "2020-08-28T03:34:07.576850Z"
},
"papermill": {
"duration": 0.758789,
"end_time": "2020-08-28T03:34:07.577029",
"exception": false,
"start_time": "2020-08-28T03:34:06.818240",
"status": "completed"
},
"scrolled": true,
"slideshow": {
"slide_type": "slide"
},
"tags": [
"remove_cell"
]
},
"outputs": [],
"source": [
"# Extract data from Google Sheet as pandas dataframe\n",
"sheet = client.open(\"COVID Daily Metrics\").sheet1\n",
"data = sheet.get_all_records()\n",
"result = pd.DataFrame(data).set_index(\"Date\")"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"execution": {
"iopub.execute_input": "2020-08-28T03:34:07.603738Z",
"iopub.status.busy": "2020-08-28T03:34:07.603280Z",
"iopub.status.idle": "2020-08-28T03:34:08.487966Z",
"shell.execute_reply": "2020-08-28T03:34:08.488656Z"
},
"papermill": {
"duration": 0.901126,
"end_time": "2020-08-28T03:34:08.488832",
"exception": false,
"start_time": "2020-08-28T03:34:07.587706",
"status": "completed"
},
"scrolled": true,
"tags": [
"remove_input"
]
},
"outputs": [
{
"data": {
"text/html": [
"<style type=\"text/css\" >\n",
" #T_54b614cc_e8df_11ea_ae05_42010a8a0004 th {\n",
" text-align: center;\n",
" }#T_54b614cc_e8df_11ea_ae05_42010a8a0004row0_col0,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row1_col0,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row2_col0,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row3_col0,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row4_col0,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row5_col0,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row6_col0,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row7_col0{\n",
" width: 20em;\n",
" text-align: center;\n",
" font-weight: bold;\n",
" }#T_54b614cc_e8df_11ea_ae05_42010a8a0004row0_col1,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row0_col2,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row0_col3,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row0_col4,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row0_col5,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row0_col6,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row1_col1,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row1_col2,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row1_col3,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row1_col4,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row1_col5,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row1_col6,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row2_col1,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row2_col2,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row2_col3,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row2_col4,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row2_col5,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row2_col6,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row3_col1,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row3_col2,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row3_col3,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row3_col4,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row3_col5,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row3_col6,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row4_col1,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row4_col2,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row4_col3,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row4_col4,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row4_col5,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row4_col6,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row5_col1,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row5_col2,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row5_col3,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row5_col4,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row5_col5,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row5_col6,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row6_col1,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row6_col2,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row6_col3,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row6_col4,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row6_col5,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row6_col6,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row7_col1,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row7_col2,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row7_col3,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row7_col4,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row7_col5,#T_54b614cc_e8df_11ea_ae05_42010a8a0004row7_col6{\n",
" width: 20em;\n",
" text-align: center;\n",
" }</style><table id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004\" ><thead> <tr> <th class=\"col_heading level0 col0\" >Date</th> <th class=\"col_heading level0 col1\" >Daily tests (per 100,000)¹</th> <th class=\"col_heading level0 col2\" >Case rate (per 100,000)²</th> <th class=\"col_heading level0 col3\" >Testing positivity (%)³</th> <th class=\"col_heading level0 col4\" >Change in hospitalizations (%)⁴</th> <th class=\"col_heading level0 col5\" >ICU beds available (%)</th> <th class=\"col_heading level0 col6\" >Ventilators (available (%)</th> </tr></thead><tbody>\n",
" <tr>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row0_col0\" class=\"data row0 col0\" >2020-08-27</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row0_col1\" class=\"data row0 col1\" >213.4</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row0_col2\" class=\"data row0 col2\" >133.4</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row0_col3\" class=\"data row0 col3\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row0_col4\" class=\"data row0 col4\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row0_col5\" class=\"data row0 col5\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row0_col6\" class=\"data row0 col6\" > ✔</td>\n",
" </tr>\n",
" <tr>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row1_col0\" class=\"data row1 col0\" >2020-08-26</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row1_col1\" class=\"data row1 col1\" >219.7</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row1_col2\" class=\"data row1 col2\" >133.2</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row1_col3\" class=\"data row1 col3\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row1_col4\" class=\"data row1 col4\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row1_col5\" class=\"data row1 col5\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row1_col6\" class=\"data row1 col6\" > ✔</td>\n",
" </tr>\n",
" <tr>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row2_col0\" class=\"data row2 col0\" >2020-08-25</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row2_col1\" class=\"data row2 col1\" >222.1</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row2_col2\" class=\"data row2 col2\" >134.1</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row2_col3\" class=\"data row2 col3\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row2_col4\" class=\"data row2 col4\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row2_col5\" class=\"data row2 col5\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row2_col6\" class=\"data row2 col6\" > ✔</td>\n",
" </tr>\n",
" <tr>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row3_col0\" class=\"data row3 col0\" >2020-08-24</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row3_col1\" class=\"data row3 col1\" >227.3</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row3_col2\" class=\"data row3 col2\" >138.0</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row3_col3\" class=\"data row3 col3\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row3_col4\" class=\"data row3 col4\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row3_col5\" class=\"data row3 col5\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row3_col6\" class=\"data row3 col6\" > ✔</td>\n",
" </tr>\n",
" <tr>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row4_col0\" class=\"data row4 col0\" >2020-08-23</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row4_col1\" class=\"data row4 col1\" >232.7</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row4_col2\" class=\"data row4 col2\" >136.7</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row4_col3\" class=\"data row4 col3\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row4_col4\" class=\"data row4 col4\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row4_col5\" class=\"data row4 col5\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row4_col6\" class=\"data row4 col6\" > ✔</td>\n",
" </tr>\n",
" <tr>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row5_col0\" class=\"data row5 col0\" >2020-08-22</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row5_col1\" class=\"data row5 col1\" >210.4</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row5_col2\" class=\"data row5 col2\" >138.7</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row5_col3\" class=\"data row5 col3\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row5_col4\" class=\"data row5 col4\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row5_col5\" class=\"data row5 col5\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row5_col6\" class=\"data row5 col6\" > ✔</td>\n",
" </tr>\n",
" <tr>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row6_col0\" class=\"data row6 col0\" >2020-08-21</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row6_col1\" class=\"data row6 col1\" >208.7</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row6_col2\" class=\"data row6 col2\" >138.5</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row6_col3\" class=\"data row6 col3\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row6_col4\" class=\"data row6 col4\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row6_col5\" class=\"data row6 col5\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row6_col6\" class=\"data row6 col6\" > ✔</td>\n",
" </tr>\n",
" <tr>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row7_col0\" class=\"data row7 col0\" >2020-08-20</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row7_col1\" class=\"data row7 col1\" >214.5</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row7_col2\" class=\"data row7 col2\" >148.8</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row7_col3\" class=\"data row7 col3\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row7_col4\" class=\"data row7 col4\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row7_col5\" class=\"data row7 col5\" > ✔</td>\n",
" <td id=\"T_54b614cc_e8df_11ea_ae05_42010a8a0004row7_col6\" class=\"data row7 col6\" > ✔</td>\n",
" </tr>\n",
" </tbody></table>"
],
"text/plain": [
"<pandas.io.formats.style.Styler at 0x7f5a2ee75fd0>"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Style the pandas dataframe\n",
"d = dict(selector=\"th\",\n",
" props=[('text-align', 'center')])\n",
"\n",
"result.reset_index().style\\\n",
" .set_properties(**{'width':'20em', 'text-align':'center'})\\\n",
" .set_properties(subset=['Date'], **{'font-weight': 'bold'})\\\n",
" .set_table_styles([d])\\\n",
" .set_precision(1)\\\n",
" .hide_index()"
]
},
{
"cell_type": "markdown",
"metadata": {
"papermill": {
"duration": 0.010476,
"end_time": "2020-08-28T03:34:08.510408",
"exception": false,
"start_time": "2020-08-28T03:34:08.499932",
"status": "completed"
},
"tags": []
},
"source": [
"<sup>Notes: (1) 7 day average with a 7-day lag. (2) 14 day average. (3) 7 day average with a 7-day lag. (4) Change in 3 day average.</sup>"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"execution": {
"iopub.execute_input": "2020-08-28T03:34:08.556669Z",
"iopub.status.busy": "2020-08-28T03:34:08.554861Z",
"iopub.status.idle": "2020-08-28T03:34:08.558366Z",
"shell.execute_reply": "2020-08-28T03:34:08.557917Z"
},
"papermill": {
"duration": 0.037675,
"end_time": "2020-08-28T03:34:08.558491",
"exception": false,
"start_time": "2020-08-28T03:34:08.520816",
"status": "completed"
},
"tags": [
"remove_input"
]
},
"outputs": [
{
"data": {
"text/markdown": [
"Table last updated by CDPH on August 27, 2020."
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"md(update_tag)"
]
},
{
"cell_type": "markdown",
"metadata": {
"papermill": {
"duration": 0.010869,
"end_time": "2020-08-28T03:34:08.580264",
"exception": false,
"start_time": "2020-08-28T03:34:08.569395",
"status": "completed"
},
"tags": []
},
"source": [
"## Tracking county closures in Santa Barbara"
]
},
{
"cell_type": "markdown",
"metadata": {
"papermill": {
"duration": 0.010648,
"end_time": "2020-08-28T03:34:08.601693",
"exception": false,
"start_time": "2020-08-28T03:34:08.591045",
"status": "completed"
},
"tags": []
},
"source": [
"The state of California is using a data-driven approach informed by scientific evidence to tailor its response to COVID-19. Three dimensions of concern are monitored to assess whether a county should be placed on the County Monitoring List:\n",
" 1. Elevated Disease Transmission\n",
" 2. Increasing Hospitalization\n",
" 3. Limited Hospital Capacity\n",
"\n",
"Once a county appears on the County Monitoring List for three consecutive days, indoor operations in the sectors listed in Section 3 of the [July 13th State Health Officer Order](https://www.cdph.ca.gov/Programs/CID/DCDC/CDPH%20Document%20Library/COVID-19/SHO%20Order%20Dimming%20Entire%20State%207-13-2020.pdf) must close.\n",
"\n",
"This table tracks where Santa Barbara stands in terms of the criteria for inclusion on the County Monitoring List. As of 20 August 2020, the criteria for inclusion on the monitoring list are:\n",
"\n",
"* Case rate >100 OR (Case rate >25 AND Positivity >8%)\n",
"* \\>10% increase in hospitalizations\n",
"* <20% ICU beds available OR <25% ventilators available\n",
"\n",
"If Santa Barbara meets the criteria for removal from the County Monitoring List for a certain metric, then a checkmark ✔ is displayed in the table.\n",
"\n",
"Read more at <https://covid19.ca.gov/roadmap-counties/>.\n",
"\n",
"Data source for county metrics: https://www.cdph.ca.gov/Programs/CID/DCDC/Pages/COVID-19/COVID19CountyDataTable.aspx."
]
},
{
"cell_type": "markdown",
"metadata": {
"papermill": {
"duration": 0.010576,
"end_time": "2020-08-28T03:34:08.623754",
"exception": false,
"start_time": "2020-08-28T03:34:08.613178",
"status": "completed"
},
"tags": []
},
"source": [
"**See the code used to scrape the data: https://github.com/walice/COVID-SB/.**"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"execution": {
"iopub.execute_input": "2020-08-28T03:34:08.651172Z",
"iopub.status.busy": "2020-08-28T03:34:08.650654Z",
"iopub.status.idle": "2020-08-28T03:34:08.654041Z",
"shell.execute_reply": "2020-08-28T03:34:08.654418Z"
},
"papermill": {
"duration": 0.019952,
"end_time": "2020-08-28T03:34:08.654568",
"exception": false,
"start_time": "2020-08-28T03:34:08.634616",
"status": "completed"
},
"tags": [
"remove_cell"
]
},
"outputs": [
{
"data": {
"application/javascript": [
"IPython.notebook.save_notebook()\n"
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%javascript\n",
"IPython.notebook.save_notebook()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"execution": {
"iopub.execute_input": "2020-08-28T03:34:08.683451Z",
"iopub.status.busy": "2020-08-28T03:34:08.682988Z",
"iopub.status.idle": "2020-08-28T03:34:09.722588Z",
"shell.execute_reply": "2020-08-28T03:34:09.723483Z"
},
"papermill": {
"duration": 1.058365,
"end_time": "2020-08-28T03:34:09.723647",
"exception": false,
"start_time": "2020-08-28T03:34:08.665282",
"status": "completed"
},
"slideshow": {
"slide_type": "skip"
},
"tags": [
"remove_cell"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[NbConvertApp] Converting notebook index.ipynb to html\r\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[NbConvertApp] Writing 358914 bytes to index.html\r\n"
]
}
],
"source": [
"# Convert Jupyter Notebook to HTML\n",
"! jupyter nbconvert \"index.ipynb\" --to html --TagRemovePreprocessor.enabled=True --TagRemovePreprocessor.remove_cell_tags=\"['remove_cell']\" --TagRemovePreprocessor.remove_input_tags=\"['remove_input']\" --no-prompt"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"execution": {
"iopub.execute_input": "2020-08-28T03:34:09.752122Z",
"iopub.status.busy": "2020-08-28T03:34:09.751615Z",
"iopub.status.idle": "2020-08-28T03:34:09.754024Z",
"shell.execute_reply": "2020-08-28T03:34:09.754408Z"
},
"papermill": {
"duration": 0.018911,
"end_time": "2020-08-28T03:34:09.754557",
"exception": false,
"start_time": "2020-08-28T03:34:09.735646",
"status": "completed"
},
"tags": [
"remove_cell"
]
},
"outputs": [],
"source": [
"# Create daily commit message\n",
"now = datetime.datetime.now()\n",
"commit_message = \"Last scraped on \" + str(now)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2020-08-27T12:00:29.987558Z",
"iopub.status.busy": "2020-08-27T12:00:29.987015Z",
"iopub.status.idle": "2020-08-27T12:00:34.846574Z",
"shell.execute_reply": "2020-08-27T12:00:34.845372Z"
},
"papermill": {
"duration": null,
"end_time": null,
"exception": false,
"start_time": "2020-08-28T03:34:09.765808",
"status": "running"
},
"tags": [
"remove_cell"
]
},
"outputs": [],
"source": [
"# Deploy to GitHub\n",
"! git add .\n",
"! echo $commit_message > commit_message.txt\n",
"! git commit -F commit_message.txt\n",
"! git push"
]
}
],
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
},
"papermill": {
"duration": null,
"end_time": null,
"environment_variables": {},
"exception": null,
"input_path": "/home/alice_lepissier/COVID-SB/index.ipynb",
"output_path": "/home/alice_lepissier/COVID-SB/index.ipynb",
"parameters": {},
"start_time": "2020-08-28T03:33:57.385844",
"version": "2.1.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment