From f954d7fbb488f78716f1890bac20896d5b3d3f8c Mon Sep 17 00:00:00 2001 From: DIYgod Date: Fri, 7 Dec 2018 02:10:11 +0800 Subject: [PATCH] add shanbay checkin, close #1235 #1239 --- docs/README.md | 4 ++++ router.js | 3 +++ routes/keep/user.js | 2 +- routes/shanbay/checkin.js | 46 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 routes/shanbay/checkin.js diff --git a/docs/README.md b/docs/README.md index 80205fa241..4c5e9f24e4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2527,3 +2527,7 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看 ### 虎嗅 + +### 扇贝 + + diff --git a/router.js b/router.js index 289f3d8c70..166e176c7a 100644 --- a/router.js +++ b/router.js @@ -900,4 +900,7 @@ router.get('/huxiu/tag/:id', require('./routes/huxiu/tag')); router.get('/steam/search/:params', require('./routes/steam/search')); router.get('/steam/news/:appids', require('./routes/steam/news')); +// 扇贝 +router.get('/shanbay/checkin/:id', require('./routes/shanbay/checkin')); + module.exports = router; diff --git a/routes/keep/user.js b/routes/keep/user.js index dbad23c8cb..28db27c3bb 100644 --- a/routes/keep/user.js +++ b/routes/keep/user.js @@ -15,7 +15,7 @@ module.exports = async (ctx) => { const data = response.data.data.entries.reduce((all, current) => all.concat(current.entries)); ctx.state.data = { - title: `Keep 动态 - ${data[0].author.username}`, + title: `${data[0].author.username} 的 Keep 动态`, link: `https://show.gotokeep.com/users/${id}`, language: 'zh-cn', item: diff --git a/routes/shanbay/checkin.js b/routes/shanbay/checkin.js new file mode 100644 index 0000000000..56127eae41 --- /dev/null +++ b/routes/shanbay/checkin.js @@ -0,0 +1,46 @@ +const axios = require('axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const username = await ctx.cache.tryGet(`shanbayuser${id}`, async () => { + const response = await axios({ + method: 'get', + url: `https://web.shanbay.com/web/checkin/achievement?user_id=${id}`, + }); + const $ = cheerio.load(response.data); + return $('#user-info-area .name').text(); + }); + + const response = await axios({ + method: 'get', + url: `https://apiv3.shanbay.com/uc/checkin/logs?page=1&user_id=${id}`, + headers: { + Referer: `https://web.shanbay.com/web/wechat/calendar/?user_id=${id}`, + }, + }); + + const data = response.data.objects; + + ctx.state.data = { + title: `${username} 的扇贝打卡`, + link: `https://web.shanbay.com/web/wechat/calendar/?user_id=${id}`, + item: + data && + data.map((item) => { + let action = ''; + item.tasks.forEach((task, index) => { + const minute = Math.floor(task.used_time / 60); + const second = task.used_time - minute * 60; + action += `${index === 0 ? '' : ';'}${task.operation}了 ${task.num} ${task.unit}${task.name},学习时间 ${minute} 分 ${second} 秒`; + }); + return { + title: `${username} 的第 ${item.checkin_days_num} 天打卡`, + pubDate: new Date(`${item.date} 00:00:00+08`), + guid: item.id, + description: action, + }; + }), + }; +};