diff --git a/docs/government.md b/docs/government.md index 4f5710a0fe..2538c2a07b 100644 --- a/docs/government.md +++ b/docs/government.md @@ -4,6 +4,27 @@ pageClass: routes # 政务消息 +## 国家新闻出版广电总局 + +### 游戏审批结果 + + + +| 栏目 | channel | +| :------------------: | :---------------: | +| 进口网络游戏审批信息 | importednetgame | +| 进口电子游戏审批信息 | importedvideogame | +| 国产网络游戏审批信息 | domesticnetgame | +| 游戏审批变更信息 | gamechange | + +| 描述 | detail | +| :------------------------------------: | :--------------: | +| 留空,返回栏目所有文章 | | +| new,返回栏目第一篇文章内容 | new | +| 某个文章标题的一部分,返回这篇文章内容 | 例:2020 年 1 月 | + + + ## 联合国 ### 安理会否决了决议 diff --git a/lib/router.js b/lib/router.js index b7e3e5ed13..3c2cc5fbd6 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1120,6 +1120,9 @@ router.get('/gov/mee/gs', require('./routes/gov/mee/gs')); // 中华人民共和国外交部 router.get('/gov/fmprc/fyrbt', require('./routes/gov/fmprc/fyrbt')); +// 国家新闻出版广电总局 +router.get('/gov/sapprft/approval/:channel/:detail?', require('./routes/gov/sapprft/7026')); + // 小黑盒 router.get('/xiaoheihe/user/:id', require('./routes/xiaoheihe/user')); router.get('/xiaoheihe/news', require('./routes/xiaoheihe/news')); diff --git a/lib/routes/gov/sapprft/7026.js b/lib/routes/gov/sapprft/7026.js new file mode 100644 index 0000000000..a5972004b7 --- /dev/null +++ b/lib/routes/gov/sapprft/7026.js @@ -0,0 +1,119 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const date = require('@/utils/date'); + +module.exports = async (ctx) => { + const { channel, detail } = ctx.params; + let id = ''; + switch (channel) { + case 'importednetgame': + id = 7027; + break; + case 'importedvideogame': + id = 7028; + break; + case 'domesticnetgame': + id = 7029; + break; + case 'gamechange': + id = 11083; + break; + default: + ctx.throw(404, 'Cannot find page'); + return; + } + const host = `http://www.sapprft.gov.cn`; + const link = host + `/sapprft/channels/` + id.toString() + `.shtml`; + const listData = await got.get(link + '?' + new Date().getTime()); // 避免CDN缓存 + const $ = cheerio.load(listData.data); + const target = $('.jar2l_list ul li'); + let url = ''; + for (const i in target) { + const item = $(target[i]).find('a'); + if (~item.text().search(detail) || detail === 'new') { + url = host + item.attr('href'); + break; + } + } + if (!detail || url === '') { + ctx.state.data = { + title: '国家新闻出版广电总局 - ' + $('.jar2l_tname').text(), + link: link, + item: await Promise.all( + target + .map(async (index, item) => { + item = $(item); + const contenlUrl = host + item.find('a').attr('href'); + const description = await ctx.cache.tryGet(contenlUrl, async () => { + const fullText = await got.get(contenlUrl); + const $$ = cheerio.load(fullText.data); + let fullTextData = ''; + $$('.jar2_editor table tbody tr') + .slice(1) + .each((index, item) => { + item = $$(item).find('td'); + fullTextData += + $$(item[0]) + .text() + .trim() + ' | '; + }); + fullTextData = '| ' + fullTextData; + return fullTextData; + }); + return { + title: item.find('a').text(), + description: description, + pubDate: date(item.find('span').text()), + link: contenlUrl, + }; + }) + .get() + ), + }; + } else { + const fullText = await got.get(url + '?' + new Date().getTime()); // 避免CDN缓存 + const $$ = cheerio.load(fullText.data); + const list = $$('.jar2_editor table tbody tr'); + + ctx.state.data = { + title: '国家新闻出版广电总局 - ' + $('.jar2l_tname').text() + ' - ' + $$('.jar2_conT').text(), + link: url, + item: await Promise.all( + list + .slice(1) + .map(async (index, item) => { + item = $$(item).find('td'); + return { + title: $$(item[0]) + .text() + .trim(), + category: $$(item[1]) + .text() + .trim(), + description: $$(item[4]) + .text() + .trim(), + author: + $$(item[2]) + .text() + .trim() + + ' | ' + + $$(item[3]) + .text() + .trim(), + pubDate: date( + $$(item[6]) + .text() + .trim() + ), + guid: $$(item[5]) + .text() + .trim(), + link: url, + }; + }) + .get() + ), + }; + } +};