This script is designed to parse and log insulin data from Google Sheets. It uses the gspread library to connect to Google Sheets and the InsulinLog class to represent individual log entries. It will take the wide log format and move it to a log sheet that is time/linear.
The Google Sheet is modeled after the Barbara Davis Center for Diabetes Daily Record Sheet.
- Python 3.12+
gspreadlibrarypython-dotenvlibraryrichlibrary
- Install the required libraries by running
pip install -r requirements.txt - Create a
service_account.jsonfile with your Google Sheets service account credentials - Create a
.envfile with your Google Sheets ID (e.g.SHEET_ID="yR4P07cGFjDlJGR8EMi5JwyTYsRu0j9sFZcdtvlvydmF") - Sheets will have a name that starts with a number e.g.
1 - Week 4/1and be formatted to match the BDC daily record sheet - Sheets will have a sheet named
Log
- Run the script by executing
python app.py - The script will parse the insulin data from the specified Google Sheets and enter them onto the
Logsheet if it doesn't already exist.
The InsulinLog class represents a single insulin log entry. It has the following fields:
date: The date of the log entrytime: The time of the log entryblood_glucose: The blood glucose valuecarbs: The carb valueinsulin: The insulin valuenotes: Any additional notests: The timestamp of the log entrytrend: The trend of the blood glucose value (e.g. "rising", "falling", etc.)trend_arrow: The trend arrow of the blood glucose value (e.g. "⬆️", "⬇️", etc.)
parse_sheets: Takes a list of sheet names and returns a list ofInsulinLoginstanceslog_to_row: Takes anInsulinLoginstance and returns a list of values to be inserted into a Google Sheets rowcompare_logs: Compares two lists of logs and returns a list of new logs that are not already present in the existing logsextract_bg_and_trend: Takes a string value and extracts the blood glucose value and trend arrow from it
- Create a Google Sheets document modeled after the BDC daily log.
- Create a Time/Linear log sheet
- Run the script by executing
python app.py - The script will parse the insulin data from the Google Sheets
- Example
XLSXsheet provided at/assets/Insulin Correction Chart & Logs.xlsx

