From 710d32f4f3164bcf5731b6a2c502b9fe477425b5 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 18 Oct 2020 23:37:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E6=96=B0=E6=B5=AA=E4=BD=93?= =?UTF-8?q?=E8=82=B2=E7=BB=BC=E5=90=88=20(#5919)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/traditional-media.md | 12 +++++++++ lib/router.js | 3 +++ lib/routes/sina/sports.js | 55 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 lib/routes/sina/sports.js diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 1ab463a0f..65a07f99d 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -707,6 +707,18 @@ category 对应的关键词有 +## 新浪体育 + +### 综合 + + + +| 排球 | 游泳 | 乒乓球 | 羽毛球 | 台球 | 田径 | 体操 | 冰雪 | 射击 | 马术 | 拳击搏击 | UFC | 其他 | +| ------ | ---- | -------- | ------ | ------- | -------- | ----- | ------ | ---- | ----- | -------- | --- | ------ | +| volley | swim | pingpang | badmin | snooker | tianjing | ticao | winter | sh | mashu | kungfu | ufc | others | + + + ## 央视新闻 ### 新闻联播 diff --git a/lib/router.js b/lib/router.js index 00499ea34..df6882aca 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/sina/sports.js b/lib/routes/sina/sports.js new file mode 100644 index 000000000..e85b63ce7 --- /dev/null +++ b/lib/routes/sina/sports.js @@ -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, + }; +};