介绍
# Garmin Connect Skill
将您所有的 Garmin 健身数据同步到 Clawdbot: - 🚶 **每日活动**:步数、心率、卡路里、活动分钟数、距离 - 😴 **睡眠**:时长、质量、深睡/REM/浅睡细分 - 🏋️ **运动**:包含距离、时长、卡路里、心率的近期活动 - ⏱️ **实时同步**:通过 cron 每 5 分钟一次
## 快速开始
### 1. 安装依赖
```bash pip install -r requirements.txt ```
### 2. OAuth 认证(一次性)
```bash python3 scripts/garmin-auth.py [email protected] your-password ```
这会将您的 OAuth 会话保存到 `~/.garth/session.json` —— 完全本地且安全。
### 3. 测试同步
```bash python3 scripts/garmin-sync.py ```
您应该会看到包含今日统计数据的 JSON 输出。
### 4. 设置 5 分钟 Cron
添加到您的 crontab:
```bash */5 * * * * /home/user/garmin-connect-clawdbot/scripts/garmin-cron.sh ```
或者手动运行:
```bash */5 * * * * python3 /home/user/garmin-connect-clawdbot/scripts/garmin-sync.py ~/.clawdbot/.garmin-cache.json ```
### 5. 在 Clawdbot 中使用
在脚本中导入并使用:
```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(安全,不存储密码) ✅ 全部指标:活动、睡眠、运动 ✅ 本地缓存(快速访问) ✅ 友好支持 Cron(5 分钟间隔) ✅ 易于集成到 Clawdbot ✅ 多用户支持
## 捕获的数据
### 每日活动 (`summary`) - `steps`:每日步数 - `heart_rate_resting`:静息心率 (bpm) - `calories`:消耗的总卡路里 - `active_minutes`:强度分钟数 - `distance_km`:行进距离
### 睡眠 (`sleep`) - `duration_hours`:总睡眠时间 - `duration_minutes`:睡眠时间(分钟) - `quality_percent`:睡眠质量评分 (0-100) - `deep_sleep_hours`:深度睡眠时长 - `rem_sleep_hours`:快速眼动 (REM) 睡眠时长 - `light_sleep_hours`:浅睡时长 - `awake_minutes`:睡眠期间清醒时间
### 运动 (`workouts`) 对于每项最近的运动: - `type`:活动类型(跑步、骑行等) - `name`:活动名称 - `distance_km`:行进距离 - `duration_minutes`:活动时长 - `calories`:消耗卡路里 - `heart_rate_avg`:平均心率 - `heart_rate_max`:最大心率
## 缓存位置
默认情况下,数据缓存于:`~/.clawdbot/.garmin-cache.json`
可通过以下方式自定义: ```bash python3 scripts/garmin-sync.py /custom/path/cache.json ```
## 文件
| 文件 | 用途 | |------|---------| | `garmin-auth.py` | OAuth 设置(运行一次) | | `garmin-sync.py` | 主同步逻辑(每 5 分钟运行一次) | | `garmin-formatter.py` | 格式化数据以供显示 | | `garmin-cron.sh` | Cron 包装脚本 | | `requirements.txt` | Python 依赖 |
## 故障排除
### OAuth 认证失败
- 检查邮箱/密码 - 在 Garmin 账户上禁用 2FA(或使用应用专用密码) - Garmin 服务器可能限制了频率 —— 请等待 5 分钟
### 没有数据显示
1. 将您的 Garmin 设备与 Garmin Connect 应用同步 2. 等待 2-3 分钟让数据同步 3. 检查数据是否出现在 Garmin Connect 网页版/应用中 4. 然后再次运行 `garmin-sync.py`
### Cron 出现权限被拒绝
```bash chmod +x scripts/garmin-cron.sh chmod +x scripts/garmin-sync.py chmod +x scripts/garmin-auth.py ```
### 找不到缓存文件
至少运行一次 `garmin-sync.py` 以创建缓存: ```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 —— 可自由使用、分叉、修改。
---
为 [Clawdbot](https://clawd.bot) 打造 | 现已于 [ClawdHub](https://clawdhub.com) 上线