From ffaca71061db48690cb39004dcad5f31c26ebbad Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Sun, 26 Nov 2023 01:48:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=AD=E5=8D=8E?= =?UTF-8?q?=E4=BA=BA=E6=B0=91=E5=85=B1=E5=92=8C=E5=9B=BD=E4=BA=A4=E9=80=9A?= =?UTF-8?q?=E8=BF=90=E8=BE=93=E9=83=A8=20(#13886)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 中华人民共和国交通运输部 * fix: url redirect --------- --- lib/v2/gov/maintainer.js | 1 + lib/v2/gov/mot/index.js | 66 +++++++++++++ lib/v2/gov/radar.js | 153 +++++++++++++++++++++++++++++ lib/v2/gov/router.js | 1 + website/docs/routes/government.mdx | 56 +++++++++++ 5 files changed, 277 insertions(+) create mode 100644 lib/v2/gov/mot/index.js diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index ed32594045..bd054bac08 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -35,6 +35,7 @@ module.exports = { '/moe/s78/:column': ['TonyRL'], '/mofcom/article/:suffix+': ['LogicJake'], '/moj/aac/news/:type?': ['TonyRL'], + '/mot/:category?': ['nczitzk'], '/news/:uid': ['EsuRt'], '/nifdc/:path+': ['nczitzk'], '/nmpa/:path+': ['TonyRL'], diff --git a/lib/v2/gov/mot/index.js b/lib/v2/gov/mot/index.js new file mode 100644 index 0000000000..9081f43c57 --- /dev/null +++ b/lib/v2/gov/mot/index.js @@ -0,0 +1,66 @@ +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 = 'tongjishuju/gonglu' } = ctx.params; + const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30; + + const rootUrl = 'https://www.mot.gov.cn'; + const currentUrl = new URL(`${category}/`, rootUrl).href; + + const { data: response } = await got(currentUrl); + + const $ = cheerio.load(response); + + let items = $('div.tab-pane a[title]') + .slice(0, limit) + .toArray() + .map((item) => { + item = $(item); + + const link = item.prop('href'); + + return { + title: item.prop('title'), + link: link.startsWith('http') ? link : new URL(item.prop('href'), currentUrl).href, + pubDate: parseDate(item.find('span.badge').text()), + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + if (/\.gov\.cn/.test(item.link)) { + const { data: detailResponse } = await got(item.link); + + const content = cheerio.load(detailResponse); + + item.title = content('meta[name="ArticleTitle"]').prop('content') || content('h1#ti').text(); + item.description = content('div.TRS_UEDITOR').html(); + item.author = [...new Set([content('meta[name="Author"]').prop('content'), content('meta[name="ContentSource"]').prop('content')])].filter((a) => a); + item.category = [ + ...new Set([content('meta[name="ColumnName"]').prop('content'), content('meta[name="ColumnType"]').prop('content'), ...(content('meta[name="Keywords"]').prop('content')?.split(/,|;/) ?? [])]), + ].filter((c) => c); + item.pubDate = timezone(parseDate(content('meta[name="PubDate"]').prop('content')), +8); + } + + return item; + }) + ) + ); + + const image = new URL($('a.navbar-brand img').prop('src'), rootUrl).href; + + ctx.state.data = { + item: items, + title: $('title').text(), + link: currentUrl, + description: $('meta[name="ColumnDescription"]').prop('content'), + language: $('html').prop('lang'), + image, + subtitle: $('meta[name="ColumnName"]').prop('content'), + author: $('meta[name="SiteName"]').prop('content'), + }; +}; diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index d41bede055..b0f0b432be 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -884,6 +884,159 @@ module.exports = { }, ], }, + 'mot.gov.cn': { + _name: '中华人民共和国交通运输部', + '.': [ + { + title: '栏目', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/:category*'], + target: (params) => { + const category = params.category; + + return `/gov/mot${category ? `/${category}` : ''}`; + }, + }, + { + title: '时政要闻', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/shizhengyaowen'], + target: '/gov/mot/shizhengyaowen', + }, + { + title: '交通要闻', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/jiaotongyaowen'], + target: '/gov/mot/jiaotongyaowen', + }, + { + title: '重要会议', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/zhongyaohuiyi'], + target: '/gov/mot/zhongyaohuiyi', + }, + { + title: '数据开放', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/sjkf'], + target: '/gov/mot/sjkf', + }, + { + title: '统计数据', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/tongjishuju'], + target: '/gov/mot/tongjishuju', + }, + { + title: '分析公报', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/fenxigongbao'], + target: '/gov/mot/fenxigongbao', + }, + { + title: '运价指数', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/yunjiazhishu'], + target: '/gov/mot/yunjiazhishu', + }, + { + title: '公路', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/tongjishuju/gonglu'], + target: '/gov/mot/tongjishuju/gonglu', + }, + { + title: '水运', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/tongjishuju/shuiyun'], + target: '/gov/mot/tongjishuju/shuiyun', + }, + { + title: '铁路', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/tongjishuju/tielu'], + target: '/gov/mot/tongjishuju/tielu', + }, + { + title: '民航', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/tongjishuju/minhang'], + target: '/gov/mot/tongjishuju/minhang', + }, + { + title: '邮政', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/tongjishuju/youzheng'], + target: '/gov/mot/tongjishuju/youzheng', + }, + { + title: '城市客运', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/tongjishuju/chengshikeyun'], + target: '/gov/mot/tongjishuju/chengshikeyun', + }, + { + title: '港口货物旅客吞吐量', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/tongjishuju/gangkouhuowulvkettl'], + target: '/gov/mot/tongjishuju/gangkouhuowulvkettl', + }, + { + title: '固定资产投资完成情况', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/tongjishuju/gudingzichantouziwcqk'], + target: '/gov/mot/tongjishuju/gudingzichantouziwcqk', + }, + { + title: '行业公报', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/fenxigongbao/hangyegongbao'], + target: '/gov/mot/fenxigongbao/hangyegongbao', + }, + { + title: '经济分析', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/fenxigongbao/jingjifenxi'], + target: '/gov/mot/fenxigongbao/jingjifenxi', + }, + { + title: '科技统计', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/fenxigongbao/kejitongji'], + target: '/gov/mot/fenxigongbao/kejitongji', + }, + { + title: '运力分析', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/fenxigongbao/yunlifenxi'], + target: '/gov/mot/fenxigongbao/yunlifenxi', + }, + { + title: '沿海散货运价指数', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/yunjiazhishu/yanhaisanhuoyjzs'], + target: '/gov/mot/yunjiazhishu/yanhaisanhuoyjzs', + }, + { + title: '出口集装箱运价指数', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/yunjiazhishu/chukoujizhuangxiangyjzs'], + target: '/gov/mot/yunjiazhishu/chukoujizhuangxiangyjzs', + }, + { + title: '长江航运指数分析', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/yunjiazhishu/changjianghangyunzsfx'], + target: '/gov/mot/yunjiazhishu/changjianghangyunzsfx', + }, + { + title: '珠江水运经济运行分析', + docs: 'https://docs.rsshub.app/routes/government#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu', + source: ['/yunjiazhishu/zhujiangshuiyunjjyxfx'], + target: '/gov/mot/yunjiazhishu/zhujiangshuiyunjjyxfx', + }, + ], + }, 'mztoday.gov.cn': { _name: '德阳市人民政府', www: [ diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index af1d1c9f2d..13d7b3fcf7 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -16,6 +16,7 @@ module.exports = function (router) { router.get('/mee/ywdt/:category?', require('./mee/ywdt')); router.get('/mem/gk/sgcc/:category?', require('./mem/sgcc')); router.get('/mfa/wjdt/:category?', require('./mfa/wjdt')); + router.get('/mot/:category*', require('./mot')); router.get('/miit/wjfb/:ministry', require('./miit/wjfb')); router.get('/miit/yjzj', require('./miit/yjzj')); router.get('/miit/zcwj', require('./miit/zcwj')); diff --git a/website/docs/routes/government.mdx b/website/docs/routes/government.mdx index e6c84c209f..be15aeb334 100644 --- a/website/docs/routes/government.mdx +++ b/website/docs/routes/government.mdx @@ -1787,6 +1787,62 @@ Language +## 中华人民共和国交通运输部 {#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu} + +### 栏目 {#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu} + + + +#### 新闻 {#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu-xin-wen} + +| 分类名 | 分类 id | +| -------- | -------------- | +| 时政要闻 | shizhengyaowen | +| 交通要闻 | jiaotongyaowen | +| 重要会议 | zhongyaohuiyi | + +#### 数据 {#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu-shu-ju} + +| 分类名 | 分类 id | +| -------- | ------------ | +| 数据开放 | sjkf | +| 统计数据 | tongjishuju | +| 分析公报 | fenxigongbao | +| 运价指数 | yunjiazhishu | + +#### 统计数据 {#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu-tong-ji-shu-ju} + +| 分类名 | 分类 id | +| -------------------- | --------------------------------- | +| 公路 | tongjishuju/gonglu | +| 水运 | tongjishuju/shuiyun | +| 铁路 | tongjishuju/tielu | +| 民航 | tongjishuju/minhang | +| 邮政 | tongjishuju/youzheng | +| 城市客运 | tongjishuju/chengshikeyun | +| 港口货物旅客吞吐量 | tongjishuju/gangkouhuowulvkettl | +| 固定资产投资完成情况 | tongjishuju/gudingzichantouziwcqk | + +#### 分析公报 {#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu-fen-xi-gong-bao} + +| 分类名 | 分类 id | +| -------- | -------------------------- | +| 行业公报 | fenxigongbao/hangyegongbao | +| 经济分析 | fenxigongbao/jingjifenxi | +| 科技统计 | fenxigongbao/kejitongji | +| 运力分析 | fenxigongbao/yunlifenxi | + +#### 运价指数 {#zhong-hua-ren-min-gong-he-guo-jiao-tong-yun-shu-bu-lan-mu-yun-jia-zhi-shu} + +| 分类名 | 分类 id | +| -------------------- | ------------------------------------ | +| 沿海散货运价指数 | yunjiazhishu/yanhaisanhuoyjzs | +| 出口集装箱运价指数 | yunjiazhishu/chukoujizhuangxiangyjzs | +| 长江航运指数分析 | yunjiazhishu/changjianghangyunzsfx | +| 珠江水运经济运行分析 | yunjiazhishu/zhujiangshuiyunjjyxfx | + + + ## 中华人民共和国教育部 {#zhong-hua-ren-min-gong-he-guo-jiao-yu-bu} ### 新闻 {#zhong-hua-ren-min-gong-he-guo-jiao-yu-bu-xin-wen}