Track water and sleep with JSON file storage
使用JSON文件简单追踪饮水量和睡眠情况。
文件:{baseDir}/health-data.json
json
{
water: [{time: ISO8601, cups: 2}],
sleep: [{time: ISO8601, action: sleep|wake}]
}
当用户说喝了X杯或喝水X杯时:
bash
node -e const fs=require(fs);const f={baseDir}/health-data.json;let d={water:[],sleep:[]};try{d=JSON.parse(fs.readFileSync(f))}catch(e){}d.water.push({time:new Date().toISOString(),cups:CUPS});fs.writeFileSync(f,JSON.stringify(d));console.log(已记录:+CUPS+杯)
将CUPS替换为用户输入的数字。
当用户说睡觉时:
bash
node -e const fs=require(fs);const f={baseDir}/health-data.json;let d={water:[],sleep:[]};try{d=JSON.parse(fs.readFileSync(f))}catch(e){}d.sleep.push({time:new Date().toISOString(),action:sleep});fs.writeFileSync(f,JSON.stringify(d));console.log(已记录:睡觉)
当用户说醒了或起床了时:
bash
node -e const fs=require(fs);const f={baseDir}/health-data.json;let d={water:[],sleep:[]};try{d=JSON.parse(fs.readFileSync(f))}catch(e){}const last=d.sleep.filter(s=>s.action===sleep).pop();d.sleep.push({time:new Date().toISOString(),action:wake});fs.writeFileSync(f,JSON.stringify(d));if(last){const h=((new Date()-new Date(last.time))/3600000).toFixed(1);console.log(已睡:+h+小时)}else{console.log(已记录:醒来)}
当用户说统计或查看统计时:
bash
node -e const fs=require(fs);const f={baseDir}/health-data.json;let d={water:[],sleep:[]};try{d=JSON.parse(fs.readFileSync(f))}catch(e){}console.log(饮水:,d.water.length,条记录);console.log(睡眠:,d.sleep.length,条记录);const today=d.water.filter(w=>new Date(w.time).toDateString()===new Date().toDateString());console.log(今日:,today.reduce((s,w)=>s+w.cups,0),杯)
更新最后一条饮水记录:
bash
node -e const fs=require(fs);const f={baseDir}/health-data.json;let d=JSON.parse(fs.readFileSync(f));d.water[d.water.length-1].cups=NEW_CUPS;fs.writeFileSync(f,JSON.stringify(d));console.log(已更新)
删除最后一条饮水记录:
bash
node -e const fs=require(fs);const f={baseDir}/health-data.json;let d=JSON.parse(fs.readFileSync(f));d.water.pop();fs.writeFileSync(f,JSON.stringify(d));console.log(已删除)
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 healthcheck-rose-1776012975 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 healthcheck-rose-1776012975 技能
skillhub install healthcheck-rose-1776012975
文件大小: 1.56 KB | 发布时间: 2026-4-13 10:32