diff --git a/docs/finance.md b/docs/finance.md index a180c2c0f..2703adb91 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -105,6 +105,18 @@ pageClass: routes +## DT 财经 + +### 数据侠专栏 + + + +| 侠创 | 纽约数据科学学院 | RS 实验所 | 阿里云天池 | +| ---- | ---------------- | --------- | ---------- | +| 5 | 6 | 9 | 10 | + + + ## 淘股吧股票论坛 ### 论坛总版 diff --git a/lib/router.js b/lib/router.js index 62b2ee020..06832e461 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/dtcj/datahero.js b/lib/routes/dtcj/datahero.js new file mode 100644 index 000000000..5a819ecbd --- /dev/null +++ b/lib/routes/dtcj/datahero.js @@ -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, + }; +};