{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Garth Migration" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import garminconnect" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Login" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Request email and password. If MFA is enabled, Garth will request it." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'mtamizi'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from getpass import getpass\n", "\n", "email = input(\"Enter email address: \")\n", "password = getpass(\"Enter password: \")\n", "\n", "garmin = garminconnect.Garmin(email, password)\n", "garmin.login()\n", "\n", "garmin.display_name" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Save session" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "GARTH_HOME = os.getenv(\"GARTH_HOME\", \"~/.garth\")\n", "garmin.garth.dump(GARTH_HOME)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get Connect stats" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'2023-09-19'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from datetime import date, timedelta\n", "\n", "yesterday = date.today() - timedelta(days=1)\n", "yesterday = yesterday.isoformat()\n", "yesterday" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_keys(['userProfileId', 'totalKilocalories', 'activeKilocalories', 'bmrKilocalories', 'wellnessKilocalories', 'burnedKilocalories', 'consumedKilocalories', 'remainingKilocalories', 'totalSteps', 'netCalorieGoal', 'totalDistanceMeters', 'wellnessDistanceMeters', 'wellnessActiveKilocalories', 'netRemainingKilocalories', 'userDailySummaryId', 'calendarDate', 'rule', 'uuid', 'dailyStepGoal', 'totalPushDistance', 'totalPushes', 'wellnessStartTimeGmt', 'wellnessStartTimeLocal', 'wellnessEndTimeGmt', 'wellnessEndTimeLocal', 'durationInMilliseconds', 'wellnessDescription', 'highlyActiveSeconds', 'activeSeconds', 'sedentarySeconds', 'sleepingSeconds', 'includesWellnessData', 'includesActivityData', 'includesCalorieConsumedData', 'privacyProtected', 'moderateIntensityMinutes', 'vigorousIntensityMinutes', 'floorsAscendedInMeters', 'floorsDescendedInMeters', 'floorsAscended', 'floorsDescended', 'intensityMinutesGoal', 'userFloorsAscendedGoal', 'minHeartRate', 'maxHeartRate', 'restingHeartRate', 'lastSevenDaysAvgRestingHeartRate', 'source', 'averageStressLevel', 'maxStressLevel', 'stressDuration', 'restStressDuration', 'activityStressDuration', 'uncategorizedStressDuration', 'totalStressDuration', 'lowStressDuration', 'mediumStressDuration', 'highStressDuration', 'stressPercentage', 'restStressPercentage', 'activityStressPercentage', 'uncategorizedStressPercentage', 'lowStressPercentage', 'mediumStressPercentage', 'highStressPercentage', 'stressQualifier', 'measurableAwakeDuration', 'measurableAsleepDuration', 'lastSyncTimestampGMT', 'minAvgHeartRate', 'maxAvgHeartRate', 'bodyBatteryChargedValue', 'bodyBatteryDrainedValue', 'bodyBatteryHighestValue', 'bodyBatteryLowestValue', 'bodyBatteryMostRecentValue', 'bodyBatteryVersion', 'abnormalHeartRateAlertsCount', 'averageSpo2', 'lowestSpo2', 'latestSpo2', 'latestSpo2ReadingTimeGmt', 'latestSpo2ReadingTimeLocal', 'averageMonitoringEnvironmentAltitude', 'restingCaloriesFromActivity', 'avgWakingRespirationValue', 'highestRespirationValue', 'lowestRespirationValue', 'latestRespirationValue', 'latestRespirationTimeGMT'])" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "garmin.get_stats(yesterday).keys()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_keys(['userProfileId', 'totalKilocalories', 'activeKilocalories', 'bmrKilocalories', 'wellnessKilocalories', 'burnedKilocalories', 'consumedKilocalories', 'remainingKilocalories', 'totalSteps', 'netCalorieGoal', 'totalDistanceMeters', 'wellnessDistanceMeters', 'wellnessActiveKilocalories', 'netRemainingKilocalories', 'userDailySummaryId', 'calendarDate', 'rule', 'uuid', 'dailyStepGoal', 'totalPushDistance', 'totalPushes', 'wellnessStartTimeGmt', 'wellnessStartTimeLocal', 'wellnessEndTimeGmt', 'wellnessEndTimeLocal', 'durationInMilliseconds', 'wellnessDescription', 'highlyActiveSeconds', 'activeSeconds', 'sedentarySeconds', 'sleepingSeconds', 'includesWellnessData', 'includesActivityData', 'includesCalorieConsumedData', 'privacyProtected', 'moderateIntensityMinutes', 'vigorousIntensityMinutes', 'floorsAscendedInMeters', 'floorsDescendedInMeters', 'floorsAscended', 'floorsDescended', 'intensityMinutesGoal', 'userFloorsAscendedGoal', 'minHeartRate', 'maxHeartRate', 'restingHeartRate', 'lastSevenDaysAvgRestingHeartRate', 'source', 'averageStressLevel', 'maxStressLevel', 'stressDuration', 'restStressDuration', 'activityStressDuration', 'uncategorizedStressDuration', 'totalStressDuration', 'lowStressDuration', 'mediumStressDuration', 'highStressDuration', 'stressPercentage', 'restStressPercentage', 'activityStressPercentage', 'uncategorizedStressPercentage', 'lowStressPercentage', 'mediumStressPercentage', 'highStressPercentage', 'stressQualifier', 'measurableAwakeDuration', 'measurableAsleepDuration', 'lastSyncTimestampGMT', 'minAvgHeartRate', 'maxAvgHeartRate', 'bodyBatteryChargedValue', 'bodyBatteryDrainedValue', 'bodyBatteryHighestValue', 'bodyBatteryLowestValue', 'bodyBatteryMostRecentValue', 'bodyBatteryVersion', 'abnormalHeartRateAlertsCount', 'averageSpo2', 'lowestSpo2', 'latestSpo2', 'latestSpo2ReadingTimeGmt', 'latestSpo2ReadingTimeLocal', 'averageMonitoringEnvironmentAltitude', 'restingCaloriesFromActivity', 'avgWakingRespirationValue', 'highestRespirationValue', 'lowestRespirationValue', 'latestRespirationValue', 'latestRespirationTimeGMT'])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "garmin.get_user_summary(yesterday).keys()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'startGMT': '2023-08-05T06:00:00.0',\n", " 'endGMT': '2023-08-05T06:15:00.0',\n", " 'steps': 0,\n", " 'pushes': 0,\n", " 'primaryActivityLevel': 'sedentary',\n", " 'activityLevelConstant': True},\n", " {'startGMT': '2023-08-05T06:15:00.0',\n", " 'endGMT': '2023-08-05T06:30:00.0',\n", " 'steps': 0,\n", " 'pushes': 0,\n", " 'primaryActivityLevel': 'sleeping',\n", " 'activityLevelConstant': False}]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "garmin.get_steps_data(yesterday)[:2]" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_keys(['startTimestampGMT', 'endTimestampGMT', 'startTimestampLocal', 'endTimestampLocal', 'floorsValueDescriptorDTOList', 'floorValuesArray'])" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "garmin.get_floors(yesterday).keys()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'calendarDate': '2023-08-05',\n", " 'totalSteps': 17945,\n", " 'totalDistance': 14352,\n", " 'stepGoal': 8560}]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "garmin.get_daily_steps(yesterday, yesterday)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_keys(['userProfilePK', 'calendarDate', 'startTimestampGMT', 'endTimestampGMT', 'startTimestampLocal', 'endTimestampLocal', 'maxHeartRate', 'minHeartRate', 'restingHeartRate', 'lastSevenDaysAvgRestingHeartRate', 'heartRateValueDescriptors', 'heartRateValues'])" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "garmin.get_heart_rates(yesterday).keys()" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_keys(['userProfileId', 'totalKilocalories', 'activeKilocalories', 'bmrKilocalories', 'wellnessKilocalories', 'burnedKilocalories', 'consumedKilocalories', 'remainingKilocalories', 'totalSteps', 'netCalorieGoal', 'totalDistanceMeters', 'wellnessDistanceMeters', 'wellnessActiveKilocalories', 'netRemainingKilocalories', 'userDailySummaryId', 'calendarDate', 'rule', 'uuid', 'dailyStepGoal', 'totalPushDistance', 'totalPushes', 'wellnessStartTimeGmt', 'wellnessStartTimeLocal', 'wellnessEndTimeGmt', 'wellnessEndTimeLocal', 'durationInMilliseconds', 'wellnessDescription', 'highlyActiveSeconds', 'activeSeconds', 'sedentarySeconds', 'sleepingSeconds', 'includesWellnessData', 'includesActivityData', 'includesCalorieConsumedData', 'privacyProtected', 'moderateIntensityMinutes', 'vigorousIntensityMinutes', 'floorsAscendedInMeters', 'floorsDescendedInMeters', 'floorsAscended', 'floorsDescended', 'intensityMinutesGoal', 'userFloorsAscendedGoal', 'minHeartRate', 'maxHeartRate', 'restingHeartRate', 'lastSevenDaysAvgRestingHeartRate', 'source', 'averageStressLevel', 'maxStressLevel', 'stressDuration', 'restStressDuration', 'activityStressDuration', 'uncategorizedStressDuration', 'totalStressDuration', 'lowStressDuration', 'mediumStressDuration', 'highStressDuration', 'stressPercentage', 'restStressPercentage', 'activityStressPercentage', 'uncategorizedStressPercentage', 'lowStressPercentage', 'mediumStressPercentage', 'highStressPercentage', 'stressQualifier', 'measurableAwakeDuration', 'measurableAsleepDuration', 'lastSyncTimestampGMT', 'minAvgHeartRate', 'maxAvgHeartRate', 'bodyBatteryChargedValue', 'bodyBatteryDrainedValue', 'bodyBatteryHighestValue', 'bodyBatteryLowestValue', 'bodyBatteryMostRecentValue', 'bodyBatteryVersion', 'abnormalHeartRateAlertsCount', 'averageSpo2', 'lowestSpo2', 'latestSpo2', 'latestSpo2ReadingTimeGmt', 'latestSpo2ReadingTimeLocal', 'averageMonitoringEnvironmentAltitude', 'restingCaloriesFromActivity', 'avgWakingRespirationValue', 'highestRespirationValue', 'lowestRespirationValue', 'latestRespirationValue', 'latestRespirationTimeGMT', 'from', 'until', 'weight', 'bmi', 'bodyFat', 'bodyWater', 'boneMass', 'muscleMass', 'physiqueRating', 'visceralFat', 'metabolicAge'])" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "garmin.get_stats_and_body(yesterday).keys()" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'startDate': '2023-08-05',\n", " 'endDate': '2023-08-05',\n", " 'dateWeightList': [],\n", " 'totalAverage': {'from': 1691193600000,\n", " 'until': 1691279999999,\n", " 'weight': None,\n", " 'bmi': None,\n", " 'bodyFat': None,\n", " 'bodyWater': None,\n", " 'boneMass': None,\n", " 'muscleMass': None,\n", " 'physiqueRating': None,\n", " 'visceralFat': None,\n", " 'metabolicAge': None}}" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "garmin.get_body_composition(yesterday)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_keys(['date', 'charged', 'drained', 'startTimestampGMT', 'endTimestampGMT', 'startTimestampLocal', 'endTimestampLocal', 'bodyBatteryValuesArray', 'bodyBatteryValueDescriptorDTOList'])" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "garmin.get_body_battery(yesterday)[0].keys()" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'from': '2023-08-05',\n", " 'until': '2023-08-05',\n", " 'measurementSummaries': [],\n", " 'categoryStats': None}" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "garmin.get_blood_pressure(yesterday)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[]" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "garmin.get_max_metrics(yesterday)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'userId': 2591602,\n", " 'calendarDate': '2023-08-05',\n", " 'valueInML': 0.0,\n", " 'goalInML': 3437.0,\n", " 'dailyAverageinML': None,\n", " 'lastEntryTimestampLocal': '2023-08-05T12:25:27.0',\n", " 'sweatLossInML': 637.0,\n", " 'activityIntakeInML': 0.0}" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "garmin.get_hydration_data(yesterday)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_keys(['userProfilePK', 'calendarDate', 'startTimestampGMT', 'endTimestampGMT', 'startTimestampLocal', 'endTimestampLocal', 'sleepStartTimestampGMT', 'sleepEndTimestampGMT', 'sleepStartTimestampLocal', 'sleepEndTimestampLocal', 'tomorrowSleepStartTimestampGMT', 'tomorrowSleepEndTimestampGMT', 'tomorrowSleepStartTimestampLocal', 'tomorrowSleepEndTimestampLocal', 'lowestRespirationValue', 'highestRespirationValue', 'avgWakingRespirationValue', 'avgSleepRespirationValue', 'avgTomorrowSleepRespirationValue', 'respirationValueDescriptorsDTOList', 'respirationValuesArray'])" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "garmin.get_respiration_data(yesterday).keys()" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_keys(['userProfilePK', 'calendarDate', 'startTimestampGMT', 'endTimestampGMT', 'startTimestampLocal', 'endTimestampLocal', 'sleepStartTimestampGMT', 'sleepEndTimestampGMT', 'sleepStartTimestampLocal', 'sleepEndTimestampLocal', 'tomorrowSleepStartTimestampGMT', 'tomorrowSleepEndTimestampGMT', 'tomorrowSleepStartTimestampLocal', 'tomorrowSleepEndTimestampLocal', 'averageSpO2', 'lowestSpO2', 'lastSevenDaysAvgSpO2', 'latestSpO2', 'latestSpO2TimestampGMT', 'latestSpO2TimestampLocal', 'avgSleepSpO2', 'avgTomorrowSleepSpO2', 'spO2ValueDescriptorsDTOList', 'spO2SingleValues', 'continuousReadingDTOList', 'spO2HourlyAverages'])" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "garmin.get_spo2_data(yesterday).keys()" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'id': 1944943000,\n", " 'typeId': 16,\n", " 'activityId': 0,\n", " 'activityName': None,\n", " 'activityStartDateTimeInGMT': None,\n", " 'actStartDateTimeInGMTFormatted': None,\n", " 'activityStartDateTimeLocal': None,\n", " 'activityStartDateTimeLocalFormatted': None,\n", " 'value': 2.0,\n", " 'prStartTimeGmt': 1691215200000,\n", " 'prStartTimeGmtFormatted': '2023-08-05T06:00:00.0',\n", " 'prStartTimeLocal': 1691193600000,\n", " 'prStartTimeLocalFormatted': '2023-08-05T00:00:00.0',\n", " 'prTypeLabelKey': None,\n", " 'poolLengthUnit': None},\n", " {'id': 2184086093,\n", " 'typeId': 3,\n", " 'activityId': 10161959373,\n", " 'activityName': 'Cuauhtémoc - Threshold',\n", " 'activityStartDateTimeInGMT': 1671549377000,\n", " 'actStartDateTimeInGMTFormatted': '2022-12-20T15:16:17.0',\n", " 'activityStartDateTimeLocal': 1671527777000,\n", " 'activityStartDateTimeLocalFormatted': '2022-12-20T09:16:17.0',\n", " 'value': 1413.6650390625,\n", " 'prStartTimeGmt': 1671549990000,\n", " 'prStartTimeGmtFormatted': '2022-12-20T15:26:30.0',\n", " 'prStartTimeLocal': None,\n", " 'prStartTimeLocalFormatted': None,\n", " 'prTypeLabelKey': None,\n", " 'poolLengthUnit': None}]" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "garmin.get_personal_record()[:2]" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[[1695103200000, 'MEASURED', 42, 2.0],\n", " [1695103380000, 'MEASURED', 42, 2.0],\n", " [1695103560000, 'MEASURED', 42, 2.0],\n", " [1695103740000, 'MEASURED', 43, 2.0],\n", " [1695103920000, 'MEASURED', 43, 2.0],\n", " [1695104100000, 'MEASURED', 43, 2.0],\n", " [1695104280000, 'MEASURED', 43, 2.0],\n", " [1695104460000, 'MEASURED', 44, 2.0],\n", " [1695104640000, 'MEASURED', 44, 2.0],\n", " [1695104820000, 'MEASURED', 44, 2.0]]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "garmin.get_all_day_stress(yesterday)['bodyBatteryValuesArray'][:10]" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "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.10.11" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }