From ce7e458910ef3e40c83da083891fa7ff02d1a09b Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 14 Feb 2021 02:53:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20DT=E8=B4=A2=E7=BB=8F=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=BE=A0=E4=B8=93=E6=A0=8F=20(#6875)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: NeverBehave --- docs/finance.md | 12 +++++++++ lib/router.js | 3 +++ lib/routes/dtcj/datahero.js | 50 +++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 lib/routes/dtcj/datahero.js 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, + }; +};