add: 政府网最新文件 (#1662)

- 从搜索页获取
- 提供一个文种分类的筛选
This commit is contained in:
ciaran
2019-03-04 19:07:43 +08:00
committed by DIYgod
parent b9e16cae89
commit 315cf7cdc1
4 changed files with 55 additions and 1 deletions

View File

@@ -2675,6 +2675,7 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
### 中国政府网
<route name="最新政策" author="SettingDust" example="/gov/zhengce/zuixin" path="/gov/zhengce/zuixin"/>
<route name="最新文件" author="ciaranchen" example="/gov/zhengce/wenjian" path="/gov/zhengce/wenjian/:pcodeJiguan?" :paramsDesc="['文种分类。 国令; 国发; 国函; 国发明电; 国办发; 国办函; 国办发明电; 其他']" />
### 联合国

View File

@@ -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'));

View File

@@ -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()
),
};
};

View File

@@ -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);