feat: add 新浪体育综合 (#5919)

This commit is contained in:
Ethan Shen 2020-10-18 23:37:53 +08:00 committed by GitHub
parent d1dd6ecca2
commit 710d32f4f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 0 deletions

View File

@ -707,6 +707,18 @@ category 对应的关键词有
<Route author="xyqfer" example="/sina/rollnews" path="/sina/rollnews" />
## 新浪体育
### 综合
<Route author="nczitzk" example="/sina/sports/volley" path="/sina/sports/:type" :paramsDesc="['运动类型,见下表']">
| 排球 | 游泳 | 乒乓球 | 羽毛球 | 台球 | 田径 | 体操 | 冰雪 | 射击 | 马术 | 拳击搏击 | UFC | 其他 |
| ------ | ---- | -------- | ------ | ------- | -------- | ----- | ------ | ---- | ----- | -------- | --- | ------ |
| volley | swim | pingpang | badmin | snooker | tianjing | ticao | winter | sh | mashu | kungfu | ufc | others |
</Route>
## 央视新闻
### 新闻联播

View File

@ -1302,6 +1302,9 @@ router.get('/sina/discovery/:type', require('./routes/sina/discovery'));
// 新浪科技滚动新闻
router.get('/sina/rollnews', require('./routes/sina/rollnews'));
// 新浪体育
router.get('/sina/sports/:type', require('./routes/sina/sports'));
// 新浪专栏创事记
router.get('/sina/csj', require('./routes/sina/chuangshiji'));

55
lib/routes/sina/sports.js Normal file
View File

@ -0,0 +1,55 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
ctx.params.type = ctx.params.type || 'volley';
let currentUrl = `https://sports.sina.com.cn/others/${ctx.params.type}.shtml`,
query = 'ul.list2 li a';
if (ctx.params.type === 'ufc') {
currentUrl = 'http://roll.sports.sina.com.cn/s_ufc_all/index.shtml';
query = '#d_list ul li span a';
}
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $(query)
.slice(0, 20)
.map((_, item) => {
item = $(item);
return {
link: item.attr('href'),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('#artibody').html();
item.title = content('meta[property="og:title"]').attr('content');
item.pubDate = new Date(content('meta[property="article:published_time"]').attr('content')).toUTCString();
return item;
})
)
);
ctx.state.data = {
title: `${$('title').text().split('_')[0]} - 新浪体育`,
link: currentUrl,
item: items,
};
};