feat: add DT财经数据侠专栏 (#6875)

Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
Ethan Shen
2021-02-13 13:53:06 -05:00
committed by GitHub
co-authored by NeverBehave
parent 2f72a46af8
commit ce7e458910
3 changed files with 65 additions and 0 deletions
+12
View File
@@ -105,6 +105,18 @@ pageClass: routes
</Route>
## DT 财经
### 数据侠专栏
<Route author="nczitzk" example="/dtcj/datahero" path="/dtcj/datahero/:category?" :paramsDesc="['分类,见下表,默认为全部']">
| 侠创 | 纽约数据科学学院 | RS 实验所 | 阿里云天池 |
| ---- | ---------------- | --------- | ---------- |
| 5 | 6 | 9 | 10 |
</Route>
## 淘股吧股票论坛
### 论坛总版
+3
View File
@@ -3920,6 +3920,9 @@ router.get('/tianyancha/hot', require('./routes/tianyancha/hot'));
// King Arthur
router.get('/kingarthur/:type', require('./routes/kingarthur/index'));
// DT 财经
router.get('/dtcj/datahero/:category?', require('./routes/dtcj/datahero'));
// 劍心.回憶
router.get('/kenshin/:category?/:type?', require('./routes/kenshin/index'));
+50
View File
@@ -0,0 +1,50 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const titles = {
5: '侠创',
6: '纽约数据科学学院',
9: 'RS实验所',
10: '阿里云天池',
};
module.exports = async (ctx) => {
const category = ctx.params.category || '';
const rootUrl = 'https://dtcj.com';
const currentUrl = `${rootUrl}/api/v1/data_hero_informations?per=15&page=1&topic_id=${category}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const list = response.data.data.map((item) => ({
title: item.title,
author: item.author,
link: `https://dtcj.com/topic/${item.id}`,
pubDate: new Date(item.date).toUTCString(),
}));
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);
item.description = content('.summary-3_j7Wt, .content-3mNFyi').html();
return item;
})
)
);
ctx.state.data = {
title: `${category ? titles[category] : '全部'} - 数据侠专栏 | DT 财经`,
link: currentUrl,
item: items,
};
};