diff --git a/lib/router.js b/lib/router.js index 70314bb906..bfb0d00072 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/csrc/fashenwei.js b/lib/routes/csrc/fashenwei.js new file mode 100644 index 0000000000..5cf2fd39a2 --- /dev/null +++ b/lib/routes/csrc/fashenwei.js @@ -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, + }; +}; diff --git a/lib/routes/csrc/news.js b/lib/routes/csrc/news.js new file mode 100644 index 0000000000..d91b703350 --- /dev/null +++ b/lib/routes/csrc/news.js @@ -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, + }; +};