add shanbay checkin, close #1235 #1239

This commit is contained in:
DIYgod
2018-12-07 02:10:11 +08:00
parent 2027080379
commit f954d7fbb4
4 changed files with 54 additions and 1 deletions

View File

@@ -2527,3 +2527,7 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看
### 虎嗅
<route name="标签" author="xyqfer" example="/huxiu/tag/291" path="/huxiu/tag/:id" :paramsDesc="['标签 id']" />
### 扇贝
<route name="打卡" author="DIYgod" example="/shanbay/checkin/ddwej" path="/shanbay/checkin/:id" :paramsDesc="['用户 id']" />

View File

@@ -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;

View File

@@ -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:

46
routes/shanbay/checkin.js Normal file
View File

@@ -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,
};
}),
};
};