sparky
Use sparky to interact with a self-hosted SparkyFitness server — log food, exercise, weight, steps, and mood.
Install
- - Homebrew (macOS/Linux): INLINECODE1
- Build from source (requires Go 1.21+):
git clone https://github.com/aronjanosch/sparky-cli
cd sparky-cli
go build -o sparky .
sudo mv sparky /usr/local/bin/
- - Pre-built binaries: https://github.com/aronjanosch/sparky-cli/releases (Linux, macOS, Windows — amd64/arm64)
Setup (once)
- -
sparky config set-url <url> — e.g. INLINECODE3 - INLINECODE4
- INLINECODE5
- INLINECODE6 — verify connection
Food
- - Search:
sparky food search "chicken breast" [-l 10] — local DB first, falls back to Open Food Facts; shows Brand column - Search by barcode:
sparky food search --barcode 4061458284547 — exact product lookup, no ambiguity - Log by name: INLINECODE9
- Log by barcode:
sparky food log --barcode 4061458284547 -m lunch -q 113 -u g — most reliable, no brand guessing - Log by ID:
sparky food log --id <uuid> -m lunch -q 150 -u g — skips search, unambiguous - Pick result:
sparky food log "Hähnchenbrust" --pick 2 — select Nth search result instead of prompting - Create custom:
sparky food create "My Meal" --calories 450 --protein 28 --carbs 42 --fat 16 — adds a custom food to your library; defaults to 100g serving; optional: --fiber, --sugar, --sodium, --saturated-fat, --brand, --serving-size, --serving-unit - Diary: INLINECODE14
- Delete entry:
sparky food delete <uuid> — removes a diary entry - Remove from library:
sparky food remove <uuid> — purge a food from your local library (get UUID via sparky -j food search)
Exercise
- - Search:
sparky exercise search "bench press" [-l 10] — local DB first, falls back to Free Exercise DB - Search external only:
sparky exercise search --external "pushup" — bypasses local cache - Log by name: INLINECODE20
- Log by ID:
sparky exercise log --id <uuid> --set 10x80@8 --set 10x80@9 — skips search, unambiguous - Sets format:
REPS[xWEIGHT][@RPE] — e.g. 10x80@8 = 10 reps, 80 kg, RPE 8; 10x80 or 10@8 also valid - Notes: INLINECODE26
- Diary: INLINECODE27
- Delete: INLINECODE28
Check-ins
- - Weight: INLINECODE29
- Steps: INLINECODE30
- Mood: INLINECODE31
- Diary:
sparky checkin diary [-d YYYY-MM-DD] — shows biometrics + mood together
Summary & trends
- -
sparky summary [-s YYYY-MM-DD] [-e YYYY-MM-DD] — nutrition/exercise/wellbeing totals (default: last 7 days) - INLINECODE34 — day-by-day nutrition table
Agentic workflow (always prefer --id to avoid ambiguity)
Exercise — search first, then log by ID:
CODEBLOCK1
Food — preferred agentic workflow:
CODEBLOCK2
Custom food (when you have nutrition facts and it's not in the DB):
CODEBLOCK3
Notes
- -
-j / --json is a root-level flag: sparky -j food diary, not INLINECODE38 - Always verify brand in search results before logging — Open Food Facts has many products with identical names
- INLINECODE39 is the most reliable option when the product has a scannable barcode
- INLINECODE40 selects the Nth result (1-based); exact local name match bypasses
--pick entirely - In JSON mode with ambiguous results, the CLI always picks
results[0] — use --id in scripts to be safe - Both search commands fall back to online providers automatically; matches are added to your library on first log
- Weight is stored in kg; lbs are auto-converted (
166 lbs → 75.30 kg) - Full UUIDs for delete: INLINECODE45
- Meal options:
breakfast, lunch, dinner, snacks (default: snacks)
sparky
使用 sparky 与自托管的 SparkyFitness 服务器交互——记录食物、运动、体重、步数和心情。
安装
- - Homebrew (macOS/Linux): brew tap aronjanosch/tap && brew install sparky-cli
- 从源码构建 (需要 Go 1.21+):
git clone https://github.com/aronjanosch/sparky-cli
cd sparky-cli
go build -o sparky .
sudo mv sparky /usr/local/bin/
- - 预编译二进制文件: https://github.com/aronjanosch/sparky-cli/releases (Linux, macOS, Windows — amd64/arm64)
设置 (一次性)
- - sparky config set-url — 例如 sparky config set-url https://sparky.example.com
- sparky config set-key
- sparky config show
- sparky ping — 验证连接
食物
- - 搜索: sparky food search chicken breast [-l 10] — 优先本地数据库,回退到 Open Food Facts;显示品牌列
- 按条码搜索: sparky food search --barcode 4061458284547 — 精确产品查询,无歧义
- 按名称记录: sparky food log chicken breast -m lunch -q 150 -u g [-d YYYY-MM-DD]
- 按条码记录: sparky food log --barcode 4061458284547 -m lunch -q 113 -u g — 最可靠,无需猜测品牌
- 按 ID 记录: sparky food log --id -m lunch -q 150 -u g — 跳过搜索,无歧义
- 选择结果: sparky food log Hähnchenbrust --pick 2 — 选择第 N 个搜索结果而非提示
- 创建自定义: sparky food create My Meal --calories 450 --protein 28 --carbs 42 --fat 16 — 添加自定义食物到您的库;默认以 100g 为一份;可选: --fiber, --sugar, --sodium, --saturated-fat, --brand, --serving-size, --serving-unit
- 日记: sparky food diary [-d YYYY-MM-DD]
- 删除条目: sparky food delete — 移除日记条目
- 从库中移除: sparky food remove — 从本地库中清除食物 (通过 sparky -j food search 获取 UUID)
运动
- - 搜索: sparky exercise search bench press [-l 10] — 优先本地数据库,回退到 Free Exercise DB
- 仅搜索外部: sparky exercise search --external pushup — 绕过本地缓存
- 按名称记录: sparky exercise log Pushups [--duration 45] [--calories 400] [-d YYYY-MM-DD]
- 按 ID 记录: sparky exercise log --id --set 10x80@8 --set 10x80@9 — 跳过搜索,无歧义
- 组数格式: REPS[xWEIGHT][@RPE] — 例如 10x80@8 = 10 次,80 公斤,RPE 8;10x80 或 10@8 也有效
- 备注: sparky exercise log Pushups --notes felt strong
- 日记: sparky exercise diary [-d YYYY-MM-DD]
- 删除: sparky exercise delete
签到
- - 体重: sparky checkin weight 75.5 [-u kg|lbs] [-d YYYY-MM-DD]
- 步数: sparky checkin steps 9500 [-d YYYY-MM-DD]
- 心情: sparky checkin mood 8 [-n notes] [-d YYYY-MM-DD]
- 日记: sparky checkin diary [-d YYYY-MM-DD] — 同时显示生物指标和心情
摘要与趋势
- - sparky summary [-s YYYY-MM-DD] [-e YYYY-MM-DD] — 营养/运动/健康总计 (默认: 最近 7 天)
- sparky trends [-n 30] — 逐日营养表
智能工作流 (始终优先使用 --id 以避免歧义)
运动 — 先搜索,然后按 ID 记录:
1. 查找候选;如需绕过本地缓存可使用 --external
sparky -j exercise search --external pushup
每个结果都有 is_local: true/false
is_local: true → id 是 UUID → 直接使用 --id
is_local: false → id 是源字符串 → 先按精确名称记录以导入,
然后再次搜索获取 UUID
2a. 本地运动
sparky -j exercise log --id
--set 3x10@8
2b. 外部运动 (首次记录时导入,然后切换到 --id)
sparky -j exercise log Pushups --set 3x10
sparky -j exercise search Pushups # 现在 is_local: true
sparky -j exercise log --id --set 3x10
食物 — 推荐智能工作流:
选项 A: 条码 (最可靠)
sparky food log --barcode 4061458284547 -q 113 -u g -m lunch
选项 B: 搜索 → 检查品牌+宏量营养素 → 按 --id 记录
sparky -j food search Hähnchenbrust
检查结果中的品牌和卡路里;选择正确的
sparky food log --id -q 400 -u g -m dinner
选项 C: 使用 --pick N 搜索 (当品牌列显示正确时)
sparky food log Hähnchenbrust --pick 3 -q 400 -u g -m dinner
从本地库移除错误导入
sparky -j food search bad product # 获取食物的 id (UUID)
sparky food remove
自定义食物 (当您有营养信息且数据库中不存在时):
食材/饮料 — 每 100g/ml 的营养信息 (默认)
sparky -j food create Craft Beer --calories 43 --protein 0.5 --carbs 3.6 --fat 0 --serving-unit ml
sparky -j food log --id -q 330 -m dinner
餐食 (Cookidoo, Chefkoch 等) — 每份的营养信息,明确指定
sparky -j food create Lasagna --calories 450 --protein 28 --carbs 42 --fat 16 --serving-size 1 --serving-unit serving
sparky -j food log --id -q 1 -m dinner
注意
- - -j / --json 是根级别标志: sparky -j food diary,而非 sparky food diary -j
- 记录前始终验证搜索结果中的品牌 — Open Food Facts 中有许多同名产品
- 当产品有可扫描条码时,--barcode 是最可靠的选项
- --pick N 选择第 N 个结果 (从 1 开始);精确本地名称匹配完全绕过 --pick
- 在 JSON 模式下出现歧义结果时,CLI 始终选择 results[0] — 在脚本中使用 --id 以确保安全
- 两个搜索命令都会自动回退到在线提供商;首次记录时匹配项会添加到您的库中
- 体重以公斤存储;磅会自动转换 (166 lbs → 75.30 kg)
- 删除时使用完整 UUID: sparky -j food diary | jq .[0].id
- 餐食选项: breakfast, lunch, dinner, snacks (默认: snacks)