fix(route): 深圳证券交易所最新规则 (#8284)

This commit is contained in:
Ethan Shen
2021-11-27 15:53:36 +08:00
committed by GitHub
parent 62d0e09826
commit 713253bed4
6 changed files with 70 additions and 46 deletions

View File

@@ -2166,7 +2166,6 @@ router.get('/sse/disclosure/:query?', lazyloadRouteHandler('./routes/sse/disclos
// 深圳证券交易所 // 深圳证券交易所
router.get('/szse/notice', lazyloadRouteHandler('./routes/szse/notice')); router.get('/szse/notice', lazyloadRouteHandler('./routes/szse/notice'));
router.get('/szse/inquire/:type', lazyloadRouteHandler('./routes/szse/inquire')); router.get('/szse/inquire/:type', lazyloadRouteHandler('./routes/szse/inquire'));
router.get('/szse/rule', lazyloadRouteHandler('./routes/szse/rule'));
router.get('/szse/projectdynamic/:type?/:stage?/:status?', lazyloadRouteHandler('./routes/szse/projectdynamic')); router.get('/szse/projectdynamic/:type?/:stage?/:status?', lazyloadRouteHandler('./routes/szse/projectdynamic'));
// 前端艺术家每日整理&&飞冰早报 // 前端艺术家每日整理&&飞冰早报

View File

@@ -1,45 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const currentUrl = `http://www.szse.cn/lawrules/rule/new/`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('ul.newslist li')
.slice(0, 10)
.map((_, item) => {
item = $(item);
const s = item.find('script').html();
return {
title: s.match(/var curTitle ='(.*?)';/)[1],
link: `http://www.szse.cn/lawrules/rule${s.match(/var curHref = '..(.*?)';/)[1]}`,
pubDate: new Date(item.find('span.time').text().trim()).toUTCString(),
};
})
.get();
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('#desContent').html();
return item;
})
)
);
ctx.state.data = {
title: '深圳证券交易所 - 最新规则',
link: currentUrl,
item: items,
};
};

View File

@@ -0,0 +1,3 @@
module.exports = {
'/rule': ['nczitzk'],
};

13
lib/v2/szse/radar.js Normal file
View File

@@ -0,0 +1,13 @@
module.exports = {
'szse.cn': {
_name: '深圳证券交易所',
'.': [
{
title: '最新规则',
docs: 'https://docs.rsshub.app/other.html#shen-zhen-zheng-quan-jiao-yi-suo-zui-xin-gui-ze',
source: ['/lawrules/rule/new', '/'],
target: '/szse/rule',
},
],
},
};

3
lib/v2/szse/router.js Normal file
View File

@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/rule', require('./rule'));
};

51
lib/v2/szse/rule.js Normal file
View File

@@ -0,0 +1,51 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const rootUrl = 'http://www.szse.cn';
const currentUrl = `${rootUrl}/api/search/content`;
const response = await got({
method: 'post',
url: currentUrl,
form: {
keyword: '',
time: 0,
range: 'title',
'channelCode[]': 'szserulesAllRulesBuss',
currentPage: 1,
pageSize: 30,
scope: 0,
},
});
const list = response.data.data.map((item) => ({
title: item.doctitle,
link: item.docpuburl,
pubDate: parseDate(item.docpubtime),
}));
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('#desContent').html();
return item;
})
)
);
ctx.state.data = {
title: '最新规则 - 深圳证券交易所',
link: `${rootUrl}/lawrules/rule/new`,
item: items,
};
};