feat: add World Economic Forum reports (#5717)
Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
parent
3f5fc5d7fa
commit
0481bff284
|
|
@ -15,3 +15,19 @@ pageClass: routes
|
|||
### US Stock News
|
||||
|
||||
<RouteEn author="HenryQW" example="/finviz/news/AAPL" path="/finviz/news/:ticker" :paramsDesc="['The stock ticker']"/>
|
||||
|
||||
## World Economic Forum
|
||||
|
||||
### Report
|
||||
|
||||
<RouteEn author="nczitzk" example="/weforum/report" path="/weforum/report/:lang?/:year?/:platform?" :paramsDesc="['Language, see below, `en` by default', 'Year, filter by year, all by default', 'Platform, filter by platform, all by default']">
|
||||
|
||||
Languages
|
||||
|
||||
| English | Español | Français | 中文 | 日本語 |
|
||||
| ------- | ------- | -------- | ---- | ------ |
|
||||
| en | es | fr | cn | jp |
|
||||
|
||||
See filters in [Report](https://www.weforum.org/reports) for Year and Platform these two parameters.
|
||||
|
||||
</RouteEn>
|
||||
|
|
|
|||
|
|
@ -62,6 +62,22 @@ pageClass: routes
|
|||
|
||||
<Route author="nczitzk" example="/gelonghui/keyword/ 早报" path="/gelonghui/keyword/:keyword" :paramsDesc="[' 搜索关键字']/>
|
||||
|
||||
## 世界经济论坛
|
||||
|
||||
### 报告
|
||||
|
||||
<Route author="nczitzk" example="/weforum/report" path="/weforum/report/:lang?/:year?/:platform?" :paramsDesc="['语言,见下表,默认为 `en`', '年份,对应年份过滤条件,默认为 `所有`', '平台,对应平台过滤条件,默认为 `所有`']">
|
||||
|
||||
语言
|
||||
|
||||
| English | Español | Français | 中文 | 日本語 |
|
||||
| ------- | ------- | -------- | ---- | ------ |
|
||||
| en | es | fr | cn | jp |
|
||||
|
||||
年份 和 平台 这两个参数请参见 [报告页](https://www.weforum.org/reports) 过滤条件处。
|
||||
|
||||
</Route>
|
||||
|
||||
## 淘股吧股票论坛
|
||||
|
||||
### 论坛总版
|
||||
|
|
|
|||
|
|
@ -3241,6 +3241,9 @@ router.get('/appsales/:caty?/:time?', require('./routes/appsales/index'));
|
|||
// CGTN
|
||||
router.get('/cgtn/top', require('./routes/cgtn/top'));
|
||||
|
||||
// World Economic Forum
|
||||
router.get('/weforum/report/:lang?/:year?/:platform?', require('./routes/weforum/report'));
|
||||
|
||||
// Nobel Prize
|
||||
router.get('/nobelprize/:caty?', require('./routes/nobelprize/index'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
ctx.params.lang = ctx.params.lang || 'www';
|
||||
ctx.params.platform = ctx.params.platform || '';
|
||||
ctx.params.year = ctx.params.year || '';
|
||||
|
||||
const rootUrl = `https://${ctx.params.lang === 'en' ? 'www' : ctx.params.lang}.weforum.org`;
|
||||
const currentUrl = `${rootUrl}/reports?platform=${ctx.params.platform}&year=${ctx.params.year}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('.report-listing-tout__content')
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find('.report-listing-tout__title').text(),
|
||||
link: `${rootUrl}${item.find('.report-listing-tout__cta').attr('href')}`,
|
||||
description: `<a href="${item.find('.report__link').attr('href')}">Download PDF</a>`,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
content('.report__meta').remove();
|
||||
|
||||
item.description += content('.report__display-info').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue