Garmin Connect 与Clawdbot 的集成:通过 OAuth 每5分钟同步健身数据(步数、心率、卡路里、训练、睡眠)。
Sync all your Garmin fitness data to Clawdbot:
bash
pip install -r requirements.txt
bash
python3 scripts/garmin-auth.py your-email@gmail.com your-password
This saves your OAuth session to ~/.garth/session.json — fully local and secure.
bash
python3 scripts/garmin-sync.py
You should see JSON output with today's stats.
Add to your crontab:
bash
*/5 * * * * /home/user/garmin-connect-clawdbot/scripts/garmin-cron.sh
Or manually:
bash
*/5 * * * * python3 /home/user/garmin-connect-clawdbot/scripts/garmin-sync.py ~/.clawdbot/.garmin-cache.json
Import and use in your scripts:
python
from scripts.garmin_formatter import format_all, get_as_dict
# Get all formatted data
print(format_all())
# Or get raw dict
data = get_as_dict()
print(f"Steps today: {data['summary']['steps']}")
✅ OAuth-based (secure, no password storage) ✅ All metrics: activity, sleep, workouts ✅ Local caching (fast access) ✅ Cron-friendly (5-minute intervals) ✅ Easy Clawdbot integration ✅ Multi-user support
summary)#steps: Daily step countheart_rate_resting: Resting heart rate (bpm)calories: Total calories burnedactive_minutes: Intensity minutesdistance_km: Distance traveledsleep)#duration_hours: Total sleep timeduration_minutes: Sleep in minutesquality_percent: Sleep quality score (0-100)deep_sleep_hours: Deep sleep durationrem_sleep_hours: REM sleep durationlight_sleep_hours: Light sleep durationawake_minutes: Time awake during sleepworkouts)#For each recent workout:
type: Activity type (Running, Cycling, etc.)name: Activity namedistance_km: Distance traveledduration_minutes: Duration of activitycalories: Calories burnedheart_rate_avg: Average heart rateheart_rate_max: Max heart rateBy default, data is cached at: ~/.clawdbot/.garmin-cache.json
Customize with:
bash
python3 scripts/garmin-sync.py /custom/path/cache.json
FilePurposegarmin-auth.pyOAuth setup (run once)garmin-sync.pyMain sync logic (run every 5 min)garmin-formatter.pyFormat data for displaygarmin-cron.shCron wrapper scriptrequirements.txtPython dependencies
garmin-sync.py againbash
chmod +x scripts/garmin-cron.sh
chmod +x scripts/garmin-sync.py
chmod +x scripts/garmin-auth.py
Run garmin-sync.py at least once to create cache:
bash
python3 scripts/garmin-sync.py
python
from scripts.garmin_formatter import format_all, get_as_dict
# Get formatted output
print(format_all())
# Get raw data
data = get_as_dict()
if data:
print(f"Sleep: {data['sleep']['duration_hours']}h")
print(f"Steps: {data['summary']['steps']:,}")
MIT — Use, fork, modify freely.