feat(route): add 澎湃明查 (#9380)

* feat(route): add 澎湃明查

* fix: 839studio routes

* docs: update example url

* fix: parseDate
This commit is contained in:
Ethan Shen 2022-03-25 22:05:27 +08:00 committed by GitHub
parent c91a4cdd1d
commit 8ecad32db2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 196 additions and 54 deletions

View File

@ -1186,7 +1186,7 @@ category 对应的关键词有
### 频道
<Route author="xyqfer nczitzk" example="/thepaper/channel/27224" path="/thepaper/channel/:id" :paramsDesc="['频道 id可在频道页 URL 中找到']">
<Route author="xyqfer nczitzk" example="/thepaper/channel/25950" path="/thepaper/channel/:id" :paramsDesc="['频道 id可在频道页 URL 中找到']">
| 视频 | 时事 | 财经 | 思想 | 澎湃号 | 生活 |
| ----- | ----- | ----- | ----- | ----- | ----- |
@ -1198,6 +1198,10 @@ category 对应的关键词有
<Route author="nczitzk" example="/thepaper/list/25457" path="/thepaper/list/:id" :paramsDesc="['列表 id可在列表页 URL 中找到']"/>
### 明查
<Route author="nczitzk" example="/thepaper/factpaper" path="/thepaper/factpaper/:status?" :paramsDesc="['状态 id可选 `1` 即 有定论 或 `0` 即 核查中,默认为 `1`']"/>
### 澎湃美数组作品集
<Route author="umm233" example="/thepaper/839studio/2" path="/thepaper/839studio/:id?" :paramsDesc="['分类 id 可选,默认订阅全部分类']">

View File

@ -848,13 +848,13 @@ router.get('/xclient/app/:name', lazyloadRouteHandler('./routes/xclient/app'));
router.get('/embassy/:country/:city?', lazyloadRouteHandler('./routes/embassy/index'));
// 澎湃新闻
router.get('/thepaper/featured', lazyloadRouteHandler('./routes/thepaper/featured'));
router.get('/thepaper/channel/:id', lazyloadRouteHandler('./routes/thepaper/channel'));
router.get('/thepaper/list/:id', lazyloadRouteHandler('./routes/thepaper/list'));
// router.get('/thepaper/featured', lazyloadRouteHandler('./routes/thepaper/featured'));
// router.get('/thepaper/channel/:id', lazyloadRouteHandler('./routes/thepaper/channel'));
// router.get('/thepaper/list/:id', lazyloadRouteHandler('./routes/thepaper/list'));
// 澎湃美数课
router.get('/thepaper/839studio', lazyloadRouteHandler('./routes/thepaper/839studio/studio.js'));
router.get('/thepaper/839studio/:id', lazyloadRouteHandler('./routes/thepaper/839studio/category.js'));
// router.get('/thepaper/839studio', lazyloadRouteHandler('./routes/thepaper/839studio/studio.js'));
// router.get('/thepaper/839studio/:id', lazyloadRouteHandler('./routes/thepaper/839studio/category.js'));
// 电影首发站
router.get('/dysfz', lazyloadRouteHandler('./routes/dysfz/index'));

View File

@ -1,48 +0,0 @@
const cheerio = require('cheerio');
const date = require('@/utils/date');
const got = require('@/utils/got');
module.exports = {
ProcessFeed: async (query, link, ctx) => {
const res = await got.get(link);
const $ = cheerio.load(res.data);
const list = $(query).slice(0, 10).get();
return Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
const itemUrl = `https://m.thepaper.cn/${$(item).find('a').eq(0).attr('href')}`;
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const res = await got.get(itemUrl);
const content = cheerio.load(res.data);
let description, pubDate;
if (content('div.news_video_msg').length > 0) {
description = content('#vdetail_sum').html();
pubDate = content('div.news_video_msg').html().split('&#xA0;&#xA0;')[0];
} else if (content('#slider_wrapper_ul').length > 0) {
description = '';
pubDate = new Date(date($(item).find('div.list_item_extra span').eq(1).text())).toUTCString();
} else {
description = content('div.newsdetail_content').html();
pubDate = new Date(content('div.date').text().trim().split('来源:')[0].trim() + ' GMT+8').toUTCString();
}
const single = {
title: content('title').text(),
link: itemUrl,
description,
pubDate,
author: content('div.author').text(),
};
return Promise.resolve(single);
})
);
},
};

View File

@ -0,0 +1,61 @@
const got = require('@/utils/got');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const status = parseInt(ctx.params.status ?? '1');
const rootUrl = 'https://www.factpaper.cn';
const apiRootUrl = 'https://api.factpaper.cn';
const currentUrl = `${apiRootUrl}/fact-check/front/proveList`;
const response = await got({
method: 'post',
url: currentUrl,
json: {
pageNum: 1,
pageSize: 20,
status,
},
});
let items = response.data.data.list.map((item) => ({
title: item.title,
guid: item.proveId,
link: `${rootUrl}/detail?id=${item.proveId}`,
pubDate: timezone(parseDate(item.publishTime), +8),
}));
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'post',
url: `${apiRootUrl}/fact-check/front/proveInfo`,
json: {
proveId: item.guid,
},
});
const data = detailResponse.data.data;
item.author = data.userName;
item.description = art(path.join(__dirname, 'templates/factpaper.art'), {
content: data.content,
checkinfo: data.checkInfoList,
finalCheckInfo: data.finalCheckInfo,
});
return item;
})
)
);
ctx.state.data = {
title: `澎湃明查 - ${status === 1 ? '有定论' : '核查中'}`,
link: rootUrl,
item: items,
};
};

View File

@ -0,0 +1,8 @@
module.exports = {
'/839studio/:id': ['umm233'],
'/839studio': ['umm233'],
'/channel/:id': ['xyqfer', 'nczitzk'],
'/featured': ['HenryQW', 'nczitzk'],
'/factpaper/:status?': ['nczitzk'],
'/list/:id': ['nczitzk'],
};

42
lib/v2/thepaper/radar.js Normal file
View File

@ -0,0 +1,42 @@
module.exports = {
'thepaper.cn': {
_name: '澎湃新闻',
'.': [
{
title: '首页头条',
docs: 'https://docs.rsshub.app/traditional-media.html#peng-pai-xin-wen-shou-ye-tou-tiao',
source: ['/'],
target: '/thepaper/featured',
},
{
title: '频道',
docs: 'https://docs.rsshub.app/traditional-media.html#peng-pai-xin-wen-pin-dao',
source: ['/'],
target: (params, url) => `/thepaper/channel/${new URL(url).search(/channel_(\d+)/)}`,
},
{
title: '列表',
docs: 'https://docs.rsshub.app/traditional-media.html#peng-pai-xin-wen-lie-biao',
source: ['/'],
target: (params, url) => `/thepaper/channel/${new URL(url).search(/list_(\d+)/)}`,
},
{
title: '澎湃美数组作品集',
docs: 'https://docs.rsshub.app/traditional-media.html#peng-pai-xin-wen-peng-pai-mei-shu-zuo-pin-ji',
source: ['/'],
target: '/thepaper/839studio/:id',
},
],
},
'factpaper.cn': {
_name: '澎湃新闻',
'.': [
{
title: '明查',
docs: 'https://docs.rsshub.app/traditional-media.html#peng-pai-xin-wen-ming-cha',
source: ['/'],
target: '/thepaper/factpaper/:status',
},
],
},
};

View File

@ -0,0 +1,8 @@
module.exports = function (router) {
router.get('/839studio', require('./839studio/studio'));
router.get('/839studio/:id', require('./839studio/category'));
router.get('/channel/:id', require('./channel'));
router.get('/featured', require('./featured'));
router.get('/factpaper/:status?', require('./factpaper'));
router.get('/list/:id', require('./list'));
};

View File

@ -0,0 +1,12 @@
<h1>发起求证</h1>
{{@ content }}
{{if checkinfo}}
<h1>一起核查</h1>
{{each checkinfo check}}
{{@ check.content }}
{{/each}}
{{/if}}
{{if finalCheckInfo}}
<h1>有定论了</h1>
{{@ finalCheckInfo.content }}
{{/if}}

55
lib/v2/thepaper/utils.js Normal file
View File

@ -0,0 +1,55 @@
const cheerio = require('cheerio');
const date = require('@/utils/date');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const got = require('@/utils/got');
module.exports = {
ProcessFeed: async (query, link, ctx) => {
const res = await got(link);
const $ = cheerio.load(res.data);
const list = $(query).slice(0, 10).get();
return Promise.all(
list.map((item) => {
const $ = cheerio.load(item);
const itemUrl = `https://m.thepaper.cn/${$(item).find('a').eq(0).attr('href')}`;
return ctx.cache.tryGet(itemUrl, async () => {
const res = await got(itemUrl);
const content = cheerio.load(res.data);
let description, pubDate;
if (content('div.news_video_msg').length > 0) {
description = content('#vdetail_sum').html();
pubDate = timezone(
parseDate(
content('div.news_video_msg')
.html()
.replace(/&nbsp;/gi, '')
.split('<br>')[0]
),
+8
);
} else if (content('#slider_wrapper_ul').length > 0) {
description = '';
pubDate = new Date(date($(item).find('div.list_item_extra span').eq(1).text())).toUTCString();
} else {
description = content('div.newsdetail_content').html();
pubDate = timezone(parseDate(content('div.date').text().trim().split('来源:')[0].trim()), +8);
}
const single = {
title: content('title').text(),
link: itemUrl,
description,
pubDate,
author: content('div.author').text(),
};
return single;
});
})
);
},
};