feat(route): add 陕西省科学技术厅 (#10115)

* feat(route): add 陕西省科学技术厅

* fix typo

* fix: pubDate

* fix typo
This commit is contained in:
Ethan Shen 2022-07-05 19:40:48 +08:00 committed by GitHub
parent f19aa220d1
commit d3a5949402
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 0 deletions

View File

@ -366,6 +366,18 @@ pageClass: routes
<Route author="sgqy" example="/go.jp/mofa" path="/go.jp/mofa"/>
## 陕西省人民政府
### 陕西省科学技术厅
<Route author="nczitzk" example="/gov/shaanxi/kjt" path="/gov/shaanxi/kjt/:id?" :paramsDesc="['分类,见下表,默认为通知公告']">
| 科技头条 | 工作动态 | 基层科技 | 科技博览 | 媒体聚焦 | 通知公告 |
| ---- | ---- | ---- | ---- | ---- | ---- |
| 1061 | 24 | 27 | 25 | 28 | 221 |
</Route>
## 上海市人民政府
### 上海市职业能力考试院 考试项目

View File

@ -22,6 +22,7 @@ module.exports = {
'/beijing/jw/tzgg': ['nczitzk'],
'/beijing/kw/:channel': ['Fatpandac'],
'/hebei/czt/xwdt/:category?': ['nczitzk'],
'/shaanxi/kjt/:id?': ['nczitzk'],
'/shenzhen/hrss/szksy/:caty/:page?': ['zlasd'],
'/shenzhen/zzb/:caty/:page?': ['zlasd'],
'/shanghai/rsj/ksxm': ['Fatpandac'],

View File

@ -520,6 +520,17 @@ module.exports = {
},
],
},
'shaanxi.gov.cn': {
_name: '陕西省人民政府',
kjt: [
{
title: '陕西省科学技术厅',
docs: 'https://docs.rsshub.app/government.html#shan-xi-ren-min-zheng-fu-shan-xi-sheng-ke-xue-ji-shu-ting',
source: ['/view/iList.jsp', '/'],
target: (params, url) => `/gov/shaanxi/kjt/${new URL(url).searchParams.get('cat_id')}`,
},
],
},
'sz.gov.cn': {
_name: '深圳政府在线移动门户',
hrss: [

View File

@ -22,6 +22,7 @@ module.exports = function (router) {
router.get('/beijing/jw/tzgg', require('./beijing/jw/tzgg'));
router.get('/beijing/kw/:channel', require('./beijing/kw/index'));
router.get('/hebei/czt/xwdt/:category?', require('./hebei/czt'));
router.get('/shaanxi/kjt/:id?', require('./shaanxi/kjt'));
router.get('/shenzhen/hrss/szksy/:caty/:page?', require('./shenzhen/hrss/szksy/index'));
router.get('/shenzhen/zzb/:caty/:page?', require('./shenzhen/zzb/index'));
router.get('/shanghai/rsj/ksxm', require('./shanghai/rsj/ksxm'));

55
lib/v2/gov/shaanxi/kjt.js Normal file
View File

@ -0,0 +1,55 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const id = ctx.params.id ?? '221';
const rootUrl = 'https://kjt.shaanxi.gov.cn';
const currentUrl = `${rootUrl}/view/iList.jsp?cat_id=${id}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
let items = $('.textlist li a')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: `${rootUrl}${item.attr('href')}`,
pubDate: parseDate(item.prev().text()),
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('.info_content').html();
item.author = content('meta[name="Author"]').attr('content');
item.pubDate = timezone(parseDate(content('meta[name="PubDate"]').attr('content')), +8);
return item;
})
)
);
ctx.state.data = {
title: `陕西省科学技术厅 - ${$('.catnm').text()}`,
link: currentUrl,
item: items,
};
};