feat: add scboy

This commit is contained in:
totorowechat
2020-12-29 15:57:07 +08:00
parent 0c4f3084a4
commit 8376d90cca
5 changed files with 84 additions and 0 deletions

View File

@@ -2470,4 +2470,18 @@
},
],
},
'scboy.com': {
_name: 'scboy 论坛',
www: [
{
title: '帖子',
docs: 'https://docs.rsshub.app/bbs.html#scboy',
source: '',
target: (params, url) => {
const id = url.includes('thread') ? url.split('-')[1].split('.')[0] : '';
return id ? `/scboy/thread/${id}` : '';
},
},
],
},
});

View File

@@ -180,6 +180,17 @@ pageClass: routes
</Route>
## SCBOY 论坛
### 帖子
<Route author="totorowechat" example="/scboy/thread/188673" path="/scboy/thread/:tid" :paramsDesc="['帖子 tid']" radar="1">
帖子网址如果为 <https://www.scboy.com/?thread-188673.htm> 那么帖子 tid 就是 `1789863`
访问水区需要添加环境变量 `SCBOY_BBS_TOKEN`, 详情见部署页面的配置模块。 `SCBOY_BBS_TOKEN`在cookies的`bbs_token`中。
</Route>
## V2EX
### 最热 / 最新主题

View File

@@ -182,6 +182,9 @@ const calculateValue = () => {
username: envs.DIDA365_USERNAME,
password: envs.DIDA365_PASSWORD,
},
scboy: {
token: envs.SCBOY_BBS_TOKEN,
},
};
};
calculateValue();

View File

@@ -3766,4 +3766,7 @@ router.get('/sciencenet/blog/:type?/:time?/:sort?', require('./routes/sciencenet
// DailyArt
router.get('/dailyart/:language?', require('./routes/dailyart/index'));
// SCBOY
router.get('/scboy/thread/:tid', require('./routes/scboy/thread'));
module.exports = router;

View File

@@ -0,0 +1,53 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const date = require('@/utils/date');
const config = require('@/config').value;
module.exports = async (ctx) => {
const tid = ctx.params.tid;
const link = `https://www.scboy.com/?thread-${tid}.htm`;
let cookieString = 'postlist_orderby=desc';
if (config.scboy.token) {
cookieString = `postlist_orderby=desc; bbs_token=${config.scboy.token}`;
}
const res = await got.get({
method: 'get',
url: link,
responseType: 'buffer',
headers: {
Cookie: cookieString,
},
});
const $ = cheerio.load(res.data);
const title = $('h4 > span:nth-of-type(1)').text();
const list = $('li.media.post');
const count = [];
for (let i = 0; i < Math.min(list.length, 30); i++) {
count.push(i);
}
const resultItems = await Promise.all(
count.map(async (i) => {
const each = $(list[i]);
const floor = each.find('span.floor-parent').text();
const item = {
title: `${title} #${floor ? floor : ' 热门回复'}`,
link: `https://www.scboy.com/?thread-${tid}`,
description: each.find('div.message.mt-1.break-all > div:nth-of-type(1)').html(),
author: each.find('username').text(),
pubDate: date(each.find('.date').text()),
};
return Promise.resolve(item);
})
);
ctx.state.data = {
title: title,
link: `https://www.scboy.com/?thread-${tid}.htm`,
item: resultItems,
};
};