Skip to content

Commit

Permalink
feat(route): add 苏州市发展和改革委员会 (DIYgod#14214)
Browse files Browse the repository at this point in the history
* feat(route): add 苏州市发展和改革委员会

* docs: remove duplicated heading

* refactor: migrate to v2

* fix: suzhou docs

* fix: news

---------
  • Loading branch information
nczitzk authored Jan 14, 2024
1 parent 1a49f93 commit 7a94c42
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 205 deletions.
4 changes: 2 additions & 2 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,8 @@ router.get('/gov/shuju/:caty/:item', lazyloadRouteHandler('./routes/gov/shuju'))
router.get('/gov/xinwen/tujie/:caty', lazyloadRouteHandler('./routes/gov/xinwen/tujie'));

// 苏州
router.get('/gov/suzhou/news/:uid', lazyloadRouteHandler('./routes/gov/suzhou/news'));
router.get('/gov/suzhou/doc', lazyloadRouteHandler('./routes/gov/suzhou/doc'));
// router.get('/gov/suzhou/news/:uid', lazyloadRouteHandler('./routes/gov/suzhou/news'));
// router.get('/gov/suzhou/doc', lazyloadRouteHandler('./routes/gov/suzhou/doc'));

// 山西
router.get('/gov/shanxi/rst/:category', lazyloadRouteHandler('./routes/gov/shanxi/rst'));
Expand Down
39 changes: 0 additions & 39 deletions lib/routes/gov/suzhou/doc.js

This file was deleted.

142 changes: 0 additions & 142 deletions lib/routes/gov/suzhou/news.js

This file was deleted.

20 changes: 0 additions & 20 deletions lib/routes/gov/suzhou/utils.js

This file was deleted.

3 changes: 3 additions & 0 deletions lib/v2/gov/maintainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ module.exports = {
'/shenzhen/zzb/:caty/:page?': ['zlasd'],
'/sichuan/deyang/govpublicinfo/:countyName/:infoType?': ['zytomorrow'],
'/sichuan/deyang/mztoday/:infoType?': ['zytomorrow'],
'/suzhou/doc': ['EsuRt'],
'/suzhou/fg/:category?': ['nczitzk'],
'/suzhou/news/:uid': ['EsuRt', 'luyuhuang'],
'/taiyuan/rsj/:caty/:page?': ['2PoL'],
'/wuhan/sy/whyw': ['nczitzk'],
'/xinyi/:path+': ['ShuiHuo'],
Expand Down
25 changes: 25 additions & 0 deletions lib/v2/gov/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,31 @@ module.exports = {
},
],
},
'suzhou.gov.cn': {
_name: '苏州市人民政府',
fg: [
{
title: '苏州市发展和改革委员会',
docs: 'https://docs.rsshub.app/routes/government#su-zhou-shi-ren-min-zheng-fu-su-zhou-shi-fa-zhan-he-gai-ge-wei-yuan-hui',
source: ['/:category*'],
target: (params) => `/gov/suzhou/fg/${params.replace(/\.shtml/, '')}`,
},
],
www: [
{
title: '政府信息公开文件',
docs: 'https://docs.rsshub.app/routes/government#su-zhou-shi-ren-min-zheng-fu',
source: ['/szxxgk/front/xxgk_right.jsp', '/'],
target: '/gov/suzhou/doc',
},
{
title: '政府新闻',
docs: 'https://docs.rsshub.app/routes/government#su-zhou-shi-ren-min-zheng-fu',
source: ['/szsrmzf/:uid/nav_list.shtml'],
target: '/gov/suzhou/news/:uid',
},
],
},
'sz.gov.cn': {
_name: '深圳政府在线移动门户',
hrss: [
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/gov/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ module.exports = function (router) {
router.get('/shenzhen/zzb/:caty/:page?', require('./shenzhen/zzb/index'));
router.get('/sichuan/deyang/govpublicinfo/:countyName/:infoType?', require('./sichuan/deyang/govpublicinfo'));
router.get('/sichuan/deyang/mztoday/:infoType?', require('./sichuan/deyang/mztoday'));
router.get('/suzhou/doc', require('./suzhou/doc'));
router.get('/suzhou/fg/:category*', require('./suzhou/fg'));
router.get('/suzhou/news/:uid', require('./suzhou/news'));
router.get('/taiyuan/rsj/:caty/:page?', require('./taiyuan/rsj'));
router.get('/wuhan/sy/whyw', require('./wuhan/whyw'));
router.get(/xinyi(\/[\w/-]+)?/, require('./xinyi/xinyi'));
Expand Down
46 changes: 46 additions & 0 deletions lib/v2/gov/suzhou/doc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
const link = 'https://www.suzhou.gov.cn/szxxgk/front/xxgk_right.jsp';

const { data: response } = await got(link);
const $ = cheerio.load(response);
const list = $('.tr_main_value_odd')
.toArray()
.map((item) => {
item = $(item);
const title = item.find('a');
return {
title: title.attr('title'),
link: `https://www.suzhou.gov.cn${title.attr('href')}`,
pubDate: timezone(parseDate(item.find('td:nth-child(3)').text().trim()), 8),
};
});

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);

item.description = $('.article-content').html();
item.author = $('dd.addWidth:nth-child(3) div').text().trim();
item.pubDate = $('meta[name="PubDate"]').length ? timezone(parseDate($('meta[name="PubDate"]').attr('content'), 'YYYY-MM-DD HH:mm:ss'), 8) : item.pubDate;
item.category = $('.OwnerDept font')
.toArray()
.map((item) => $(item).text().trim());

return item;
})
)
);

ctx.state.data = {
title: '苏州市政府 - 政策公开文件',
link,
item: items,
};
};
62 changes: 62 additions & 0 deletions lib/v2/gov/suzhou/fg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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 { category = 'szfgw/ggl/nav_list' } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;

const rootUrl = 'https://fg.suzhou.gov.cn';
const currentUrl = new URL(`${category}.shtml`, rootUrl).href;

const { data: response } = await got(currentUrl);

const $ = cheerio.load(response);

let items = $('h4 a[title]')
.slice(0, limit)
.toArray()
.map((item) => {
item = $(item);

return {
title: item.prop('title') || item.text(),
link: new URL(item.prop('href'), rootUrl).href,
author: item.find('.author').text(),
pubDate: parseDate(item.parent().find('span.time').text().trim()),
};
});

items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: detailResponse } = await got(item.link);

const content = cheerio.load(detailResponse);

item.title = content('ucaptitle').text().trim();
item.description = content('ucapcontent').html();
item.author = content('span.ly b').text().trim();
item.pubDate = timezone(parseDate(content('meta[name="PubDate"]').prop('content')), +8);

return item;
})
)
);

const author = $('meta[name="SiteName"]').prop('content');
const subtitle = $('meta[name="ColumnName"]').prop('content');
const image = new URL($('div.logo img').prop('src'), rootUrl).href;

ctx.state.data = {
item: items,
title: `${author} - ${subtitle}`,
link: currentUrl,
description: $('meta[name="ColumnDescription"]').prop('content'),
language: $('html').prop('lang'),
image,
subtitle,
author,
};
};
Loading

0 comments on commit 7a94c42

Please sign in to comment.