diff --git a/docs/README.md b/docs/README.md index 8b66c0fe70..f28b97ba09 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2675,6 +2675,7 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的 ### 中国政府网 + ### 联合国 diff --git a/lib/router.js b/lib/router.js index 3d50138946..664d9fa731 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1012,6 +1012,7 @@ router.get('/cyzone/author/:id', require('./routes/cyzone/author')); // 政府 router.get('/gov/zhengce/zuixin', require('./routes/gov/zhengce/zuixin')); +router.get('/gov/zhengce/wenjian/:pcodeJiguan?', require('./routes/gov/zhengce/wenjian')); // 小黑盒 router.get('/xiaoheihe/user/:id', require('./routes/xiaoheihe/user')); diff --git a/lib/routes/gov/zhengce/wenjian.js b/lib/routes/gov/zhengce/wenjian.js new file mode 100644 index 0000000000..586c2e7055 --- /dev/null +++ b/lib/routes/gov/zhengce/wenjian.js @@ -0,0 +1,52 @@ +const axios = require('../../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const { pcodeJiguan } = ctx.params; + const link = `http://sousuo.gov.cn/list.htm`; + const res = await axios.get(link, { + params: { + n: 20, + sort: 'pubtime', + t: 'paper', + pcodeJiguan: pcodeJiguan ? pcodeJiguan : '', + }, + }); + const $list = cheerio.load(res.data); + + ctx.state.data = { + title: `最新文件 - 中国政府网`, + link, + item: await Promise.all( + $list('body > div.dataBox > table > tbody > tr') + .slice(1) + .map(async (_, el) => { + const item = $list(el); + + const number = item.find('td.info').next(); + const title = item.find('td.info > a'); + const href = title.attr('href'); + + const key = `gov_zhengce: ${href}`; + let description; + const value = await ctx.cache.get(key); + + if (value) { + description = value; + } else { + const contentData = await axios.get(href); + const $content = cheerio.load(contentData.data); + description = $content('#UCAP-CONTENT').html(); + ctx.cache.set(key, description, 24 * 60 * 60); + } + + return { + title: number.text() + ' | ' + title.text(), + description, + link: href, + }; + }) + .get() + ), + }; +}; diff --git a/lib/routes/gov/zhengce/zuixin.js b/lib/routes/gov/zhengce/zuixin.js index ba9e8b0ac8..d3dcf0b49d 100644 --- a/lib/routes/gov/zhengce/zuixin.js +++ b/lib/routes/gov/zhengce/zuixin.js @@ -14,7 +14,7 @@ module.exports = async (ctx) => { const $el = $list(el); const $a = $el.find('h4 a'); const href = $a.attr('href'); - const key = `zuixin_zhengce: ${href}`; + const key = `gov_zhengce: ${href}`; let description; const value = await ctx.cache.get(key);