名称: healthcheck
描述: 使用 JSON 文件存储记录饮水和睡眠情况
版本: 1.0.2
标签: 健康, 追踪
一个使用 JSON 文件记录饮水和睡眠情况的简单工具。
文件:{baseDir}/health-data.json
{
"water": [{"time": "ISO8601", "cups": 2}],
"sleep": [{"time": "ISO8601", "action": "sleep|wake"}]
}
当用户说“uống X cốc”或“uống nước X cốc”时:
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 替换为用户输入的数字。
当用户说“đi ngủ”时:
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('已记录: 入睡')"
当用户说“thức dậy”或“dậy rồi”时:
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('已记录: 醒来')}"
当用户说“thống kê”或“xem thống kê”时:
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),'杯')"
更新最近一条饮水记录:
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('已更新')"
删除最近一条饮水记录:
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('已删除')"