diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 4468d0f9d1..b5ca7410cf 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -315,6 +315,12 @@ category 对应的关键词有 ## 央视新闻 +### 新闻联播 + + +新闻联播内容摘要。 + + ### 专题 diff --git a/lib/router.js b/lib/router.js index f30406903e..3e45033a56 100644 --- a/lib/router.js +++ b/lib/router.js @@ -290,6 +290,8 @@ router.get('/tingshuitz/wuhan', require('./routes/tingshuitz/wuhan')); router.get('/mihoyo/bh3/:type', require('./routes/mihoyo/bh3')); router.get('/mihoyo/bh2/:type', require('./routes/mihoyo/bh2')); +// 新闻联播 +router.get('/cctv/xwlb', require('./routes/cctv/xwlb')); // 央视新闻 router.get('/cctv/:category', require('./routes/cctv/category')); diff --git a/lib/routes/cctv/xwlb.js b/lib/routes/cctv/xwlb.js new file mode 100644 index 0000000000..48834b4424 --- /dev/null +++ b/lib/routes/cctv/xwlb.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const date = require('@/utils/date'); +const cheerio = require('cheerio'); +const dayjs = require('dayjs'); +require('dayjs/locale/zh-cn'); + +module.exports = async (ctx) => { + const res = await got({ method: 'get', url: 'http://tv.cctv.com/lm/xwlb/' }); + const $ = cheerio.load(res.data); + // 解析最新一期新闻联播的日期 + const latestDate = dayjs( + date( + $('.md .mh_title > a') + .text() + .replace(/\s/g, '') + ), + { locale: 'zh-cn' } + ); + const count = []; + for (let i = 0; i < 20; i++) { + count.push(i); + } + const resultItems = await Promise.all( + count.map(async (i) => { + const newsDate = latestDate.subtract(i, 'days').set('hour', 19); + const url = `http://tv.cctv.com/lm/xwlb/day/${newsDate.format('YYYYMMDD')}.shtml`; + const item = { + title: `新闻联播 ${newsDate.format('YYYY/MM/DD')}`, + link: url, + pubDate: newsDate.toISOString(), + description: await ctx.cache.tryGet(url, async () => { + const res = await got.get(url); + const content = cheerio.load(res.data); + const alist = new Array(); + content('a').map((i, e) => { + const a = content(e); + const href = a.attr('href'); + const title = a.find('.text .title').text(); + const dur = a.find('.text .bottom').text(); + alist.push(`${title} ⏱${dur}`); + return i; + }); + return alist.join('
\n'); + }), + }; + return Promise.resolve(item); + }) + ); + + ctx.state.data = { + title: 'CCTV 新闻联播', + link: 'http://tv.cctv.com/lm/xwlb/', + item: resultItems, + }; +};