feat(route): add 东方财富网行业研究 (#12671)

* feat(route): add 东方财富研究报告

* feat(route): add 东方财富研究报告

* update: 东方财富研究报告文档

* feat(router): add 东方财富研究报告

* feat(router): add 东方财富研究报告

* fix:link add .jshtml suffix

* feat(route):add 东方财富网行业研究

* chore: data link
This commit is contained in:
飞飞鱼 2023-06-15 15:51:58 +08:00 committed by GitHub
parent 5f9e6dc6be
commit e9885dbf41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 12 deletions

View File

@ -302,9 +302,9 @@ TokenInsight 官方亦有提供 RSS可参考 <https://api.tokeninsight.com/re
<Route author="syzq" example="/eastmoney/report/strategyreport" path="/eastmoney/report/:category" :paramsDesc="['研报类型']">
| 策略报告 | 宏观研究 | 券商晨报 |
| -------------- | ----------- | ------------ |
| strategyreport | macresearch | brokerreport |
| 策略报告 | 宏观研究 | 券商晨报 | 行业研究 |
| -------------- | ----------- | ------------ | -------- |
| strategyreport | macresearch | brokerreport | industry |
</Route>

View File

@ -7,14 +7,16 @@ module.exports = async (ctx) => {
const { category = 'strategyreport' } = ctx.params;
const reportType = {
strategyreport: '策略报告',
macresearch: '宏观研究',
brokerreport: '券商晨报',
industry: '行业研报',
macresearch: '宏观研究',
strategyreport: '策略报告',
};
const linkType = {
strategyreport: 'zw_strategy',
macresearch: 'zw_macresearch',
brokerreport: 'zw_brokerreport',
industry: 'zw_industry',
macresearch: 'zw_macresearch',
strategyreport: 'zw_strategy',
};
const res = await got(`${baseUrl}/report/${category}`);
@ -23,19 +25,31 @@ module.exports = async (ctx) => {
const initData = JSON.parse(
$('script')
.text()
.match(/var initdata = (.*?);/)[1]
.match(/var initdata(.=?)(.*?);/)[2]
);
const list = initData.data.map((item) => ({
title: `${item.orgSName}】- ${item.title}`,
title: `[${item.orgSName}]${item.title}`,
link: `${baseUrl}/report/${linkType[category]}.jshtml?encodeUrl=${item.encodeUrl}`,
pubDate: parseDate(item.publishDate),
author: Array.isArray(item.author) ? item.author.join('') : '',
author: item.researcher,
}));
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);
item.link = $('.pdf-link').attr('href');
item.description = $('.ctx-content').text();
return item;
})
)
);
ctx.state.data = {
title: `东方财富网 - ${reportType[category]}`,
title: `东方财富网-${reportType[category]}`,
link: baseUrl,
item: list,
item: items,
};
};