mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 06:30:40 +08:00
feat: add 新闻联播 (#3004)
* feat: add 新闻联播 * fix: newline * use dayjs to replace luxon
This commit is contained in:
committed by
DIYgod
parent
67380a6067
commit
6842c76de1
@@ -315,6 +315,12 @@ category 对应的关键词有
|
|||||||
|
|
||||||
## 央视新闻
|
## 央视新闻
|
||||||
|
|
||||||
|
### 新闻联播
|
||||||
|
|
||||||
|
<Route author="zengxs" example="/cctv/xwlb" path="/cctv/xwlb">
|
||||||
|
新闻联播内容摘要。
|
||||||
|
</Route>
|
||||||
|
|
||||||
### 专题
|
### 专题
|
||||||
|
|
||||||
<Route author="idealclover xyqfer" example="/cctv/world" path="/cctv/:category" :paramsDesc="['分类名']">
|
<Route author="idealclover xyqfer" example="/cctv/world" path="/cctv/:category" :paramsDesc="['分类名']">
|
||||||
|
|||||||
@@ -290,6 +290,8 @@ router.get('/tingshuitz/wuhan', require('./routes/tingshuitz/wuhan'));
|
|||||||
router.get('/mihoyo/bh3/:type', require('./routes/mihoyo/bh3'));
|
router.get('/mihoyo/bh3/:type', require('./routes/mihoyo/bh3'));
|
||||||
router.get('/mihoyo/bh2/:type', require('./routes/mihoyo/bh2'));
|
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'));
|
router.get('/cctv/:category', require('./routes/cctv/category'));
|
||||||
|
|
||||||
|
|||||||
55
lib/routes/cctv/xwlb.js
Normal file
55
lib/routes/cctv/xwlb.js
Normal file
@@ -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(`<a href="${href}">${title} ⏱${dur}</a>`);
|
||||||
|
return i;
|
||||||
|
});
|
||||||
|
return alist.join('<br/>\n');
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
return Promise.resolve(item);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: 'CCTV 新闻联播',
|
||||||
|
link: 'http://tv.cctv.com/lm/xwlb/',
|
||||||
|
item: resultItems,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user