mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat(route): Add stats.gov 国家统计局 (#10860)
* add new statsgov * Fix radar.js * 1. Fix the missing optional chaining operator in reg matching 2. add the missing timezone change * remove the dup $ in item * optimize url * stats.gov.cn refactored * Modify doc * more flexible pathname parsing * Fix radar data
This commit is contained in:
@@ -184,6 +184,22 @@ pageClass: routes
|
||||
|
||||
<Route author="nczitzk" example="/gov/chinatax/latest" path="/gov/chinatax/latest"/>
|
||||
|
||||
## 国家统计局
|
||||
|
||||
### 统计数据 > 最新发布
|
||||
|
||||
<Route author="bigfei" example="/gov/stats/tjsj/zxfb" path="/gov/stats/:path+" :paramsDesc="['路径,默认为 统计数据 > 最新发布']">
|
||||
|
||||
::: tip 提示
|
||||
|
||||
路径处填写对应页面 URL 中 `http://www.stats.gov.cn/` 后的字段。下面是一个例子。
|
||||
|
||||
若订阅 [统计数据 > 统计标准](http://www.stats.gov.cn/tjsj/tjbz/) 则将对应页面 URL <http://www.stats.gov.cn/tjsj/tjbz/> 中 `http://www.stats.gov.cn/` 后的字段 `tjsj/tjbz` 作为路径填入。此时路由为 [`/gov/stats/tjsj/tjbz`](https://rsshub.app/gov/stats/tjsj/tjbz)
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
||||
## 国家新闻出版广电总局(弃用)
|
||||
|
||||
### 游戏审批结果
|
||||
|
||||
@@ -33,6 +33,7 @@ module.exports = {
|
||||
'/pbc/gzlw': ['Fatpandac'],
|
||||
'/pbc/tradeAnnouncement': ['nczitzk'],
|
||||
'/pbc/zcyj': ['Fatpandac'],
|
||||
'/stats/:path+': ['bigfei'],
|
||||
// province
|
||||
'/anhui/kjt/:path?': ['nczitzk'],
|
||||
'/beijing/jw/tzgg': ['nczitzk'],
|
||||
|
||||
@@ -688,6 +688,17 @@ module.exports = {
|
||||
},
|
||||
],
|
||||
},
|
||||
'stats.gov.cn': {
|
||||
_name: '国家统计局',
|
||||
www: [
|
||||
{
|
||||
title: '统计数据 > 最新发布',
|
||||
docs: 'https://docs.rsshub.app/government.html#guo-jia-tong-ji-ju-tong-ji-shu-ju-zui-xin-fa-bu',
|
||||
source: ['/*'],
|
||||
target: (params, url) => `/gov/stats/${new URL(url).href.match(/stats\.gov\.cn\/(.*)/)[1]}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
'sz.gov.cn': {
|
||||
_name: '深圳政府在线移动门户',
|
||||
hrss: [
|
||||
|
||||
@@ -25,6 +25,7 @@ module.exports = function (router) {
|
||||
router.get('/pbc/gzlw', require('./pbc/gzlw'));
|
||||
router.get('/pbc/tradeAnnouncement', require('./pbc/tradeAnnouncement'));
|
||||
router.get('/pbc/zcyj', require('./pbc/zcyj'));
|
||||
router.get(/stats(\/[\w/-]+)?/, require('./stats'));
|
||||
// province
|
||||
router.get(/anhui\/kjt\/([\w\d/-]+)?/, require('./anhui/kjt'));
|
||||
router.get('/beijing/jw/tzgg', require('./beijing/jw/tzgg'));
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
const { parseContList, parseXilan } = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = 'http://www.stats.gov.cn';
|
||||
const defaultPath = '/tjsj/zxfb/';
|
||||
|
||||
let pathname = ctx.path.replace(/(^\/stats|\/$)/g, '');
|
||||
pathname = pathname === '' ? defaultPath : pathname.endsWith('/') ? pathname : pathname + '/';
|
||||
const currentUrl = `${rootUrl}${pathname}`;
|
||||
|
||||
const { list, title } = await parseContList(currentUrl, 'ul.center_list_contlist li a:not([id])', ctx);
|
||||
const items = await Promise.all(list.map((item) => parseXilan(item, ctx)));
|
||||
|
||||
ctx.state.data = {
|
||||
title,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
{{ each attachments }}
|
||||
<p>
|
||||
<a href="{{ $value.href }}" >{{ $value.text }}</a>
|
||||
</p>
|
||||
{{ /each}}
|
||||
@@ -0,0 +1,64 @@
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const got = require('@/utils/got');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
const parseContList = async (url, selector, ctx) => {
|
||||
const response = await got(url);
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $(selector)
|
||||
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 12)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find('.cont_tit03').text(),
|
||||
link: new URL(item.attr('href'), url).href,
|
||||
pubDate: parseDate(item.find('.cont_tit02').text(), 'YYYY-MM-DD'),
|
||||
};
|
||||
})
|
||||
.filter((item) => item.title); // exclude the empty title
|
||||
const title = $('#PL_DAOHANG')
|
||||
.text()
|
||||
.replace(/(.+)首页/, '国家统计局');
|
||||
return { list, title };
|
||||
};
|
||||
|
||||
const parseXilan = async (item, ctx) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got(item.link);
|
||||
const $ = cheerio.load(response.data);
|
||||
const title = $('.xilan_titf').text();
|
||||
item.author = title.match(/来源:(.*)发布时间/)?.[1].trim() ?? '国家统计局';
|
||||
item.pubDate = timezone(parseDate(title.match(/发布时间:(.*)/)?.[1].trim() ?? item.pubDate), +8);
|
||||
item.description = $('.xilan_con').html();
|
||||
|
||||
const attachmentTitle = $('.wenzhang_tit').filter(function () {
|
||||
return $(this).text().trim() === '相关附件';
|
||||
});
|
||||
if (attachmentTitle.length > 0) {
|
||||
const attachments = attachmentTitle
|
||||
.first()
|
||||
.next('.wenzhang_list')
|
||||
.find('a')
|
||||
.toArray()
|
||||
.map((attachment) => {
|
||||
attachment = $(attachment);
|
||||
return {
|
||||
href: new URL(attachment.attr('href'), item.link).href,
|
||||
text: attachment.text().trim(),
|
||||
};
|
||||
});
|
||||
item.description += art(path.join(__dirname, 'templates/attachments.art'), {
|
||||
attachments,
|
||||
});
|
||||
}
|
||||
return item;
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
parseXilan,
|
||||
parseContList,
|
||||
};
|
||||
Reference in New Issue
Block a user