feat: 证监会要闻、发审委公告 (#2488)

This commit is contained in:
Bing Wong
2019-06-26 02:14:42 +08:00
committed by DIYgod
parent 8d0a2b5388
commit 7dda7b176c
3 changed files with 92 additions and 0 deletions

View File

@@ -1439,6 +1439,10 @@ router.get('/8btc/:authorid', require('./routes/8btc/author'));
// VueVlog
router.get('/vuevideo/:userid', require('./routes/vuevideo/user'));
// 证监会
router.get('/csrc/news', require('./routes/csrc/news'));
router.get('/csrc/fashenwei', require('./routes/csrc/fashenwei'));
// LWN.net Alerts
router.get('/lwn/alerts/:distributor', require('./routes/lwn/alerts'));

View File

@@ -0,0 +1,45 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
module.exports = async (ctx) => {
const url = 'http://www.csrc.gov.cn/pub/zjhpublic/3300/3621/index_7401.htm';
const ori_url = 'http://www.csrc.gov.cn/pub/zjhpublic/';
const res = await got.get(url);
const $ = cheerio.load(res.data);
const list = $('.row').get();
const out = await Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
const time = $('li.fbrq').text();
const title = $('li.mc > div').text();
const sub_url = $('li.mc > div')
.find('a')
.attr('href')
.slice(6);
const itemUrl = ori_url + sub_url;
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const responses = await got.get(itemUrl);
const $d = cheerio.load(responses.data);
const single = {
title,
pubDate: new Date(time).toUTCString(),
link: itemUrl,
guid: itemUrl,
description: $d('#ContentRegion .Custom_UnionStyle').html(),
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: $('title').text(),
link: url,
item: out,
};
};

43
lib/routes/csrc/news.js Normal file
View File

@@ -0,0 +1,43 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
module.exports = async (ctx) => {
const url = 'http://www.csrc.gov.cn/pub/newsite/zjhxwfb/xwdd/';
const res = await got.get(url);
const $ = cheerio.load(res.data);
const list = $('.fl_list li').get();
const out = await Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
const time = $('span').text();
const title = $('a').text();
const sub_url = $('a')
.attr('href')
.slice(2);
const itemUrl = url + sub_url;
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const responses = await got.get(itemUrl);
const $d = cheerio.load(responses.data);
const single = {
title,
pubDate: new Date(time).toUTCString(),
link: itemUrl,
guid: itemUrl,
description: $d('.content .Custom_UnionStyle').html(),
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: $('title').text(),
link: url,
item: out,
};
};