healthcheck
2026-03-25
新闻来源:网淘吧
围观:69
电脑广告
手机广告
购买adidas上京东官方旗舰店。
健康追踪器
使用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('Da ghi: '+CUPS+' coc')"
替换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('Da ghi: di ngu')"
添加起床记录
当用户说"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('Da ngu: '+h+' gio')}else{console.log('Da ghi: thuc day')}"
查看统计
当用户说"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('Water:',d.water.length,'records');console.log('Sleep:',d.sleep.length,'records');const today=d.water.filter(w=>new Date(w.time).toDateString()===new Date().toDateString());console.log('Today:',today.reduce((s,w)=>s+w.cups,0),'cups')"
更新记录
更新最后一条饮水记录:
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('Updated')"
删除记录
删除最后一条饮水记录:
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('Deleted')"
注意事项
- 仅使用Node.js内置模块
- 文件缺失时会自动创建
- 所有时间戳均使用ISO8601格式
文章底部电脑广告
手机广告位-内容正文底部
上一篇:Google Workspace Admin
下一篇:Fathom


微信扫一扫,打赏作者吧~