Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,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 中找到']">

| 视频 | 时事 | 财经 | 思想 | 澎湃号 | 生活 |
| ----- | ----- | ----- | ----- | ----- | ----- |
Expand All @@ -1187,6 +1187,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 可选,默认订阅全部分类']">
Expand Down
10 changes: 5 additions & 5 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -847,13 +847,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'));
Expand Down
48 changes: 0 additions & 48 deletions lib/routes/thepaper/utils.js

This file was deleted.

File renamed without changes.
61 changes: 61 additions & 0 deletions lib/v2/thepaper/factpaper.js
Original file line number Diff line number Diff line change
@@ -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,
};
};
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions lib/v2/thepaper/maintainer.js
Original file line number Diff line number Diff line change
@@ -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 changes: 42 additions & 0 deletions lib/v2/thepaper/radar.js
Original file line number Diff line number Diff line change
@@ -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',
},
],
},
};
8 changes: 8 additions & 0 deletions lib/v2/thepaper/router.js
Original file line number Diff line number Diff line change
@@ -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'));
};
12 changes: 12 additions & 0 deletions lib/v2/thepaper/templates/factpaper.art
Original file line number Diff line number Diff line change
@@ -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 changes: 55 additions & 0 deletions lib/v2/thepaper/utils.js
Original file line number Diff line number Diff line change
@@ -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;
});
})
);
},
};