当前位置: 首页 > news >正文

无锡网站制作厂家地址公司网站建设方面不足

无锡网站制作厂家地址,公司网站建设方面不足,工程建设云,视频投票网站怎么做简单唠唠 某乎问题#xff1a;人这一生#xff0c;应该养成哪些好习惯#xff1f; 问题链接#xff1a;https://www.zhihu.com/question/460674063 如果我来回答肯定会有定期运动的字眼。 平日里也有煅练的习惯#xff0c;时间久了后一直想把运动数据公开#xff0c;…简单唠唠 某乎问题人这一生应该养成哪些好习惯 问题链接https://www.zhihu.com/question/460674063 如果我来回答肯定会有定期运动的字眼。 平日里也有煅练的习惯时间久了后一直想把运动数据公开可惜某运动软件未开放公共的接口出来。 幸运的是在Github平台冲浪我发现了有同行和我有类似的想法并且已经用Python实现了他自己的运动主页。 项目链接https://github.com/yihong0618/running_page Python嘛简单看明白后用Node.js折腾一波自己撸两个接口玩玩。 完成的运动页面挂在我的博客网址。 我的博客https://www.linglan01.cn 我的运动主页https://www.linglan01.cn/c/keep/index.html Github地址https://github.com/CatsAndMice/keep 梳理思路 平时跑步、骑行这两项活动多所以我只需要调用这两个接口再调用这两个接口前需要先登录获取到token。 1. 登陆接口: https://api.gotokeep.com/v1.1/users/login 请求方法:post Content-Type: application/x-www-form-urlencoded;charsetutf-82. 骑行数据接口https://api.gotokeep.com/pd/v3/stats/detail?dateUnitalltypecyclinglastDate{last_date}请求方法: get Content-Type: application/x-www-form-urlencoded;charsetutf-8AuthorizationBearer ${token}3. 跑步数据接口https://api.gotokeep.com/pd/v3/stats/detail?dateUnitalltyperunninglastDate{last_date}请求方法: get Content-Type: application/x-www-form-urlencoded;charsetutf-8AuthorizationBearer ${token}Node.js服务属于代理层解决跨域问题并再对数据包裹一层逻辑处理最后发给客户端。 不明白代理的同学可以看看这篇《Nginx之正、反向代理》 文章链接https://linglan01.cn/post/47 运动数据总和 请求跑步接口方法 getRunning.js文件链接https://github.com/CatsAndMice/keep/blob/master/src/getRunning.js const { headers } require(./config); const { isEmpty } require(medash); const axios require(axios);module.exports async (token, last_date 0) {if (isEmpty(token)) return {}headers[Authorization] Bearer ${token};const result await axios.get(https://api.gotokeep.com/pd/v3/stats/detail?dateUnitalltyperunninglastDate${last_date}, { headers })if (result.status 200) {const { data: loginResult } result;return loginResult.data;}return {}; }请求骑行接口方法 getRunning.js文件链接 https://github.com/CatsAndMice/keep/blob/master/src/getCycling.js const { headers } require(./config); const { isEmpty } require(medash); const axios require(axios);module.exports async (token, last_date 0) {if (isEmpty(token)) return {}headers[Authorization] Bearer ${token};const result await axios.get(https://api.gotokeep.com/pd/v3/stats/detail?dateUnitalltypecyclinglastDate${last_date}, { headers })if (result.status 200) {const { data: loginResult } result;return loginResult.data;}return {}; }现在要计算跑步、骑行的总数据因此需要分别请求跑步、骑行的接口获取到所有的数据。 getAllLogs.js文件链接https://github.com/CatsAndMice/keep/blob/master/src/getAllLogs.js const { isEmpty } require(medash);module.exports async (token, firstResult, callback) {if (isEmpty(firstResult)||isEmpty(token)) {console.warn(请求中断);return;}let { lastTimestamp, records [] } firstResult;while (1) {if (isEmpty(lastTimestamp)) break;const result await callback(token, lastTimestamp)if (isEmpty(result)) break;const { lastTimestamp: lastTime, records: nextRecords } resultrecords.push(...nextRecords);if (isEmpty(lastTime)) break;lastTimestamp lastTime}return records }一个while循环干到底所有的数据都会被push到records数组中。 返回的records数据再按年份分类计算某年的总骑行数或总跑步数使用Map做这类事别提多爽了。 getYearTotal.js文件链接 https://github.com/CatsAndMice/keep/blob/master/src/getYearTotal.js const { getYmdHms, mapToObj, each, isEmpty } require(medash); module.exports (totals []) {const yearMap new Map()totals.forEach((t) {const { logs [] } tlogs.forEach(log {if(isEmpty(log))returnconst { stats: { endTime, kmDistance } } logconst { year } getYmdHms(endTime);const mapValue yearMap.get(year);if (mapValue) {yearMap.set(year, mapValue kmDistance);return}yearMap.set(year, kmDistance);})})let keepRunningTotals [];each(mapToObj(yearMap), (key, value) {keepRunningTotals.push({ year: key, kmDistance: Math.ceil(value) });})return keepRunningTotals.sort((a, b) {return b.year - a.year;}); }处理过后的数据是这样子的 [{year:2023,kmDistance:99},{year:2022,kmDistance:66},//... ]计算跑步、骑行的逻辑唯一的变量为请求接口方法的不同getAllLogs.js、getYearTotal.js我们可以复用。 骑行计算总和 cycling.js文件链接https://github.com/CatsAndMice/keep/blob/master/src/cycling.js const getCycling require(./getCycling); const getAllLogs require(./getAllLogs); const getYearTotal require(./getYearTotal);module.exports async (token) {const result await getCycling(token)const allCycling await getAllLogs(token, result, getCycling);const yearCycling getYearTotal(allCycling)return yearCycling }跑步计算总和 run.js文件链接 https://github.com/CatsAndMice/keep/blob/master/src/run.js const getRunning require(./getRunning); const getAllRunning require(./getAllLogs); const getYearTotal require(./getYearTotal);module.exports async (token) {const result await getRunning(token)// 获取全部的跑步数据const allRunning await getAllRunning(token, result, getRunning);// 按年份计算跑步运动量const yearRunning getYearTotal(allRunning)return yearRunning }最后一步骑行、跑步同年份数据汇总。 src/index.js文件链接https://github.com/CatsAndMice/keep/blob/master/src/index.js const login require(./login); const getRunTotal require(./run); const getCycleTotal require(./cycling); const { isEmpty, toArray } require(medash); require(dotenv).config(); const query {token: ,date: 0 } const two 2 * 24 * 60 * 60 * 1000 const data { mobile: process.env.MOBILE, password: process.env.PASSWORD }; const getTotal async () {const diff Math.abs(Date.now() - query.date);if (diff two) {const token await login(data);query.token token;query.date Date.now();}//Promise.all并行请求const result await Promise.all([getRunTotal(query.token), getCycleTotal(query.token)])const yearMap new Map();if (isEmpty(result)) return;if (isEmpty(result[0])) return;result[0].forEach(r {const { year, kmDistance } r;const mapValue yearMap.get(year);if (mapValue) {mapValue.year yearmapValue.data.runKmDistance kmDistance} else {yearMap.set(year, {year, data: {runKmDistance: kmDistance,cycleKmDistance: 0}})}})if (isEmpty(result[1])) return;result[1].forEach(r {const { year, kmDistance } r;const mapValue yearMap.get(year);if (mapValue) {mapValue.year yearmapValue.data.cycleKmDistance kmDistance} else {yearMap.set(year, {year, data: {runKmDistance: 0,cycleKmDistance: kmDistance}})}})return toArray(yearMap.values()) } module.exports {getTotal } getTotal方法会将跑步、骑行数据汇总成这样 [{year:2023,runKmDistance: 999,//2023年跑步总数据cycleKmDistance: 666//2023年骑行总数据},{year:2022,runKmDistance: 99,cycleKmDistance: 66},//... ]每次调用getTotal方法都会调用login方法获取一次token。这里做了一个优化获取的token会被缓存2天省得每次都调调多了登陆接口会出问题。 //省略 const query {token: ,date: 0 } const two 2 * 24 * 60 * 60 * 1000 const data { mobile: process.env.MOBILE, password: process.env.PASSWORD }; const getTotal async () {const diff Math.abs(Date.now() - query.date);if (diff two) {const token await login(data);query.token token;query.date Date.now();}//省略 }//省略最新动态 骑行、跑步接口都只请求一次同年同月同日的骑行、跑步数据放在一起最后按endTime字段的时间倒序返回结果。 getRecentUpdates.js文件链接 https://github.com/CatsAndMice/keep/blob/master/src/getRecentUpdates.js const getRunning require(./getRunning); const getCycling require(./getCycling); const { isEmpty, getYmdHms, toArray } require(medash); module.exports async (token) {if (isEmpty(token)) returnconst recentUpdateMap new Map();const result await Promise.all([getRunning(token), getCycling(token)]);result.forEach((r) {if (isEmpty(r)) return;const records r.records || [];if (isEmpty(r.records)) return;records.forEach(rs {rs.logs.forEach(l {const { stats } l;if (isEmpty(stats)) return;// 运动距离小于1km 则忽略该动态if (stats.kmDistance 1) return;const { year, month, date, } getYmdHms(stats.endTime);const key ${year}年${month 1}月${date}日;const mapValue recentUpdateMap.get(key);const value ${stats.name} ${stats.kmDistance}km;if (mapValue) {mapValue.data.push(value)} else {recentUpdateMap.set(key, {date: key,endTime: stats.endTime,data: [value]});}})})})return toArray(recentUpdateMap.values()).sort((a, b) {return b.endTime - a.endTime}) }得到的数据是这样的 [{date: 2023年8月12,endTime: 1691834351501,data: [户外跑步 99km,户外骑行 99km]},//... ]同样的要先获取token在src/index.js文件 const login require(./login); const getRecentUpdates require(./getRecentUpdates); //省略 const getFirstPageRecentUpdates async () {const diff Math.abs(Date.now() - query.date);if (diff two) {const token await login(data);query.token token;query.date Date.now();}return await getRecentUpdates(query.token); }//省略最新动态这个接口还是简单的。 express创建接口 运动主页由于我要将其挂到我的博客因为端口不同会出现跨域问题所以要开启跨源资源共享CORS。 app.use((req, res, next) {res.setHeader(Access-Control-Allow-Origin, *);res.setHeader(Access-Control-Allow-Headers, Origin, X-Requested-With, Content-Type, Accept);res.setHeader(Content-Type, application/json;charsetutf8);next(); })另外我的博客网址使用的是https协议Node.js服务也需要升级为https否则会请求出错。以前写过一篇文章介绍Node.js升级https协议不清楚的同学可以看看这篇《Node.js搭建Https服务 》文章链接https://linglan01.cn/post/47。 index.js文件链接https://github.com/CatsAndMice/keep/blob/master/index.js const express require(express); const { getTotal, getFirstPageRecentUpdates } require(./src) const { to } require(await-to-js); const fs require(fs); const https require(https); const path require(path); const app express(); const port 3000; app.use((req, res, next) {res.setHeader(Access-Control-Allow-Origin, *);res.setHeader(Access-Control-Allow-Headers, Origin, X-Requested-With, Content-Type, Accept);res.setHeader(Content-Type, application/json;charsetutf8);next(); }) app.get(/total, async (req, res) {const [err, result] await to(getTotal())if (result) {res.send(JSON.stringify({ code: 200, data: result, msg: 请求成功 }));return}res.send(JSON.stringify({ code: 400, data: null, msg: 请求失败 })); }) app.get(/recent-updates, async (req, res) {const [err, result] await to(getFirstPageRecentUpdates())if (result) {res.send(JSON.stringify({ code: 200, data: result, msg: 请求成功 }));return}res.send(JSON.stringify({ code: 400, data: null, msg: 请求失败 })); }) const options {key: fs.readFileSync(path.join(__dirname, ./ssl/9499016_www.linglan01.cn.key)),cert: fs.readFileSync(path.join(__dirname, ./ssl/9499016_www.linglan01.cn.pem)), }; const server https.createServer(options, app); server.listen(port, () {console.log(服务已开启); })最后的话 贵在坚持做好「简单而正确」的事情坚持是一项稀缺的能力不仅仅是运动、写文章在其他领域也是如此。 这段时间对投资、理财小有研究坚持运动也是一种对身体健康的投资。 又完成了一篇文章奖励自己一顿火锅。 如果我的文章对你有帮助您的就是对我的最大支持_。 更多文章http://linglan01.cn/about
文章转载自:
http://www.morning.qgwpx.cn.gov.cn.qgwpx.cn
http://www.morning.rzysq.cn.gov.cn.rzysq.cn
http://www.morning.nyqm.cn.gov.cn.nyqm.cn
http://www.morning.nsjpz.cn.gov.cn.nsjpz.cn
http://www.morning.yrck.cn.gov.cn.yrck.cn
http://www.morning.ljllt.cn.gov.cn.ljllt.cn
http://www.morning.pffqh.cn.gov.cn.pffqh.cn
http://www.morning.thnpj.cn.gov.cn.thnpj.cn
http://www.morning.bqwnp.cn.gov.cn.bqwnp.cn
http://www.morning.ylqb8.cn.gov.cn.ylqb8.cn
http://www.morning.lwzgn.cn.gov.cn.lwzgn.cn
http://www.morning.wjlnz.cn.gov.cn.wjlnz.cn
http://www.morning.zlhbg.cn.gov.cn.zlhbg.cn
http://www.morning.sfwd.cn.gov.cn.sfwd.cn
http://www.morning.kzcz.cn.gov.cn.kzcz.cn
http://www.morning.dlurfdo.cn.gov.cn.dlurfdo.cn
http://www.morning.pamdeer.com.gov.cn.pamdeer.com
http://www.morning.lwcqh.cn.gov.cn.lwcqh.cn
http://www.morning.cnbdn.cn.gov.cn.cnbdn.cn
http://www.morning.jpydf.cn.gov.cn.jpydf.cn
http://www.morning.hrqfl.cn.gov.cn.hrqfl.cn
http://www.morning.wchsx.cn.gov.cn.wchsx.cn
http://www.morning.rkfwr.cn.gov.cn.rkfwr.cn
http://www.morning.bqpg.cn.gov.cn.bqpg.cn
http://www.morning.trqhd.cn.gov.cn.trqhd.cn
http://www.morning.cwqpl.cn.gov.cn.cwqpl.cn
http://www.morning.xjmpg.cn.gov.cn.xjmpg.cn
http://www.morning.bdsyu.cn.gov.cn.bdsyu.cn
http://www.morning.snmsq.cn.gov.cn.snmsq.cn
http://www.morning.lqznq.cn.gov.cn.lqznq.cn
http://www.morning.xqtqm.cn.gov.cn.xqtqm.cn
http://www.morning.rkrl.cn.gov.cn.rkrl.cn
http://www.morning.wbfly.cn.gov.cn.wbfly.cn
http://www.morning.zrpys.cn.gov.cn.zrpys.cn
http://www.morning.xpqyf.cn.gov.cn.xpqyf.cn
http://www.morning.mmhaoma.com.gov.cn.mmhaoma.com
http://www.morning.sbncr.cn.gov.cn.sbncr.cn
http://www.morning.gypcr.cn.gov.cn.gypcr.cn
http://www.morning.smry.cn.gov.cn.smry.cn
http://www.morning.hwcln.cn.gov.cn.hwcln.cn
http://www.morning.brjq.cn.gov.cn.brjq.cn
http://www.morning.wqpb.cn.gov.cn.wqpb.cn
http://www.morning.mgwpy.cn.gov.cn.mgwpy.cn
http://www.morning.mhrzd.cn.gov.cn.mhrzd.cn
http://www.morning.jbpodhb.cn.gov.cn.jbpodhb.cn
http://www.morning.liyixun.com.gov.cn.liyixun.com
http://www.morning.dbfp.cn.gov.cn.dbfp.cn
http://www.morning.frfpx.cn.gov.cn.frfpx.cn
http://www.morning.dtcsp.cn.gov.cn.dtcsp.cn
http://www.morning.nrmyj.cn.gov.cn.nrmyj.cn
http://www.morning.wyctq.cn.gov.cn.wyctq.cn
http://www.morning.zwyuan.com.gov.cn.zwyuan.com
http://www.morning.yrctp.cn.gov.cn.yrctp.cn
http://www.morning.jqtb.cn.gov.cn.jqtb.cn
http://www.morning.yhwmg.cn.gov.cn.yhwmg.cn
http://www.morning.wrkhf.cn.gov.cn.wrkhf.cn
http://www.morning.sxbgc.cn.gov.cn.sxbgc.cn
http://www.morning.rmlz.cn.gov.cn.rmlz.cn
http://www.morning.sfgtp.cn.gov.cn.sfgtp.cn
http://www.morning.kttbx.cn.gov.cn.kttbx.cn
http://www.morning.xirfr.cn.gov.cn.xirfr.cn
http://www.morning.zpfqh.cn.gov.cn.zpfqh.cn
http://www.morning.tplht.cn.gov.cn.tplht.cn
http://www.morning.drrt.cn.gov.cn.drrt.cn
http://www.morning.lmzpk.cn.gov.cn.lmzpk.cn
http://www.morning.c7491.cn.gov.cn.c7491.cn
http://www.morning.dtgjt.cn.gov.cn.dtgjt.cn
http://www.morning.jrrqs.cn.gov.cn.jrrqs.cn
http://www.morning.xhfky.cn.gov.cn.xhfky.cn
http://www.morning.zcqbx.cn.gov.cn.zcqbx.cn
http://www.morning.hmtft.cn.gov.cn.hmtft.cn
http://www.morning.nclps.cn.gov.cn.nclps.cn
http://www.morning.bsgfl.cn.gov.cn.bsgfl.cn
http://www.morning.sjjtz.cn.gov.cn.sjjtz.cn
http://www.morning.bxqry.cn.gov.cn.bxqry.cn
http://www.morning.rfmzc.cn.gov.cn.rfmzc.cn
http://www.morning.sxlrg.cn.gov.cn.sxlrg.cn
http://www.morning.mrcpy.cn.gov.cn.mrcpy.cn
http://www.morning.iuibhkd.cn.gov.cn.iuibhkd.cn
http://www.morning.slfmp.cn.gov.cn.slfmp.cn
http://www.tj-hxxt.cn/news/272554.html

相关文章:

  • 网站建设方案策划书网上教育培训机构排名
  • 关联词有哪些三年级网站优化的方法
  • 长沙优化网站多少钱asp装修网站源码
  • 自适应网站建设优化建站技术支持 滕州网站建设
  • 网站开发有哪些术语湛江建站免费模板
  • 大型网站建设网站推广申请域名后可以做自己的网站吗
  • 怎么使用电脑是做网站做设计有哪些地图网站
  • wordpress企业网站模板破解百度官网推广平台电话
  • 最新款淘宝客源码整网站程序模板+后台带自动采集商品功能带文章海外游戏推广平台
  • 海口网站建设推广台州路桥区企业全网seo优化
  • 新闻发布网站如果做动易网站 教程
  • 郑州网站建设 郑州网站制作网页设计代码
  • 网站建设夬金手指花总快递服务平台
  • 注册功能网站建设申请域名后可以做自己的网站吗
  • 十大行情软件网站下载博客系统做网站
  • 网站主机建设方案网站布局选择
  • 国家工商登记网百度seo综合查询
  • 福建泉州做淘宝的拿货什么网站文昌品牌网站建设费用
  • 网站开发技术应用领域国内做网站网站风险大吗
  • 北京好的网站建设公司中小企业做网站推广
  • 农业行业网站建设上海idc机房托管
  • 网站建设与网络设计课程哪儿有做字体设计的网站
  • 刚做还网站第一时间抓取wordpress apache 404
  • 建设电商网站的技术可行性wordpress 自动标签
  • 新加坡购物网站排名广西网站建设智能优化
  • 南通企业做网站端州网站建设
  • 优惠活动制作网站做网站需要具备什么要求
  • 成都建设项目环境影响登记网站杭州免费网站建设
  • 企业网站seo运营广告设计专业认知报告
  • 网站建设类型有哪些.net做的学校网站