feat(route): add DT财经数据洞察 (#7672)

* feat(route): add DT财经数据洞察

* fix typo

* refactor: migrate to v2

Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
This commit is contained in:
Ethan Shen 2022-02-22 20:30:40 +08:00 committed by GitHub
parent f0b4864752
commit 0022ca1d2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 102 additions and 4 deletions

View File

@ -12,6 +12,16 @@ pageClass: routes
## DT 财经
### 数据洞察
<Route author="nczitzk" example="/dtcj/datainsight" path="/dtcj/datainsight/:id?" :paramsDesc="['分类,见下表,默认为全部']">
| 城数 | NEXT 情报局 | 专业精选 |
| -- | -------- | ---- |
| 3 | 1 | 4 |
</Route>
### 数据侠专栏
<Route author="nczitzk" example="/dtcj/datahero" path="/dtcj/datahero/:category?" :paramsDesc="['分类,见下表,默认为全部']">

View File

@ -3891,8 +3891,9 @@ router.get('/jlbtc/kyc/:category?', lazyloadRouteHandler('./routes/universities/
router.get('/jlbtc/jwc/:id?', lazyloadRouteHandler('./routes/universities/jlbtc/jwc'));
router.get('/jlbtc/:category?', lazyloadRouteHandler('./routes/universities/jlbtc/index'));
// DT 财经
router.get('/dtcj/datahero/:category?', lazyloadRouteHandler('./routes/dtcj/datahero'));
// DT 财经 migrated to v2
// router.get('/dtcj/datahero/:category?', lazyloadRouteHandler('./routes/dtcj/datahero'));
// router.get('/dtcj/datainsight/:id?', lazyloadRouteHandler('./routes/dtcj/datainsight'));
// 劍心.回憶
router.get('/kenshin/:category?/:type?', lazyloadRouteHandler('./routes/kenshin/index'));

View File

@ -1,5 +1,6 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const titles = {
5: '侠创',
@ -9,7 +10,7 @@ const titles = {
};
module.exports = async (ctx) => {
const category = ctx.params.category || '';
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}`;
@ -22,7 +23,7 @@ module.exports = async (ctx) => {
title: item.title,
author: item.author,
link: `https://dtcj.com/topic/${item.id}`,
pubDate: new Date(item.date).toUTCString(),
pubDate: parseDate(item.date),
}));
const items = await Promise.all(

View File

@ -0,0 +1,53 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const id = ctx.params.id ?? '';
const rootUrl = 'https://dtcj.com';
const currentUrl = `${rootUrl}/${id ? `insighttopic/${id}` : 'datainsight'}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.info-2_P1UM a')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: `${rootUrl}${item.attr('href')}`,
};
})
.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);
item.description = content('.content-3mNFyi').html();
item.pubDate = parseDate(detailResponse.data.match(/"date":"(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}\+\d{2}:\d{2})","thumbnail_url":/)[1]);
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};

View File

@ -0,0 +1,4 @@
module.exports = {
'/datahero/:category?': ['nczitzk'],
'/datainsight/:id?': ['nczitzk'],
};

25
lib/v2/dtcj/radar.js Normal file
View File

@ -0,0 +1,25 @@
module.exports = {
'dtcj.com': {
_name: 'DT 财经',
'.': [
{
title: '数据侠专栏',
docs: 'https://docs.rsshub.app/finance.html#dt-cai-jing',
source: ['/datahero/topic'],
target: (_params, url) => `/dtcj/datahero/${new URL(url).searchParams.get('topic_id')}`,
},
{
title: '数据洞察',
docs: 'https://docs.rsshub.app/finance.html#dt-cai-jing',
source: ['/dtcj/datainsight'],
target: '/dtcj/datainsight',
},
{
title: '数据洞察',
docs: 'https://docs.rsshub.app/finance.html#dt-cai-jing',
source: ['/insighttopic/:id'],
target: '/dtcj/datainsight/:id',
},
],
},
};

4
lib/v2/dtcj/router.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/datahero/:category?', require('./datahero'));
router.get('/datainsight/:id?', require('./datainsight'));
};