From 38fbcf09f1e86b0a9f239dff32633ffe45ed36db Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Tue, 30 Jan 2024 12:28:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=AD=E5=9B=BD?= =?UTF-8?q?=E6=B1=BD=E8=BD=A6=E5=B7=A5=E4=B8=9A=E5=8D=8F=E4=BC=9A=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E4=BF=A1=E6=81=AF=E7=BD=91=20(#14339)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/v2/auto-stats/index.js | 65 +++++++++++++++++++++++++++++++++ lib/v2/auto-stats/maintainer.js | 3 ++ lib/v2/auto-stats/radar.js | 35 ++++++++++++++++++ lib/v2/auto-stats/router.js | 3 ++ website/docs/routes/other.mdx | 12 ++++++ 5 files changed, 118 insertions(+) create mode 100644 lib/v2/auto-stats/index.js create mode 100644 lib/v2/auto-stats/maintainer.js create mode 100644 lib/v2/auto-stats/radar.js create mode 100644 lib/v2/auto-stats/router.js diff --git a/lib/v2/auto-stats/index.js b/lib/v2/auto-stats/index.js new file mode 100644 index 00000000000000..a1f15953d5dc99 --- /dev/null +++ b/lib/v2/auto-stats/index.js @@ -0,0 +1,65 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const { category = 'xxkd' } = ctx.params; + const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 30; + + const rootUrl = 'http://www.auto-stats.org.cn'; + const currentUrl = new URL(`${category}.asp`, rootUrl).href; + + const { data: response } = await got(currentUrl, { + responseType: 'buffer', + }); + + const $ = cheerio.load(iconv.decode(response, 'gbk')); + + let items = $('a.dnews font') + .slice(0, limit) + .toArray() + .map((item) => { + item = $(item); + + const title = item.text(); + const pubDate = title.match(/(\d{4}(?:\/\d{1,2}){2}\s\d{1,2}(?::\d{2}){2})/)?.[1] ?? undefined; + + return { + title: title.replace(/●/, '').split(/(\d+/)[0], + link: new URL(item.parent().prop('href'), rootUrl).href, + pubDate: timezone(parseDate(pubDate, 'YYYY/M/D H:mm:ss'), +8), + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: detailResponse } = await got(item.link, { + responseType: 'buffer', + }); + + const content = cheerio.load(iconv.decode(detailResponse, 'gbk')); + + item.description = content('table tbody tr td.dd').last().html(); + + return item; + }) + ) + ); + + const subtitle = $('title').text().split(/——/).pop(); + const image = new URL('images/logo.jpg', rootUrl).href; + + ctx.state.data = { + item: items, + title: $('title').text(), + link: currentUrl, + description: subtitle, + language: 'zh', + image, + subtitle, + allowEmpty: true, + }; +}; diff --git a/lib/v2/auto-stats/maintainer.js b/lib/v2/auto-stats/maintainer.js new file mode 100644 index 00000000000000..81eb78d7328b63 --- /dev/null +++ b/lib/v2/auto-stats/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:category?': ['nczitzk'], +}; diff --git a/lib/v2/auto-stats/radar.js b/lib/v2/auto-stats/radar.js new file mode 100644 index 00000000000000..07d15a100cea0a --- /dev/null +++ b/lib/v2/auto-stats/radar.js @@ -0,0 +1,35 @@ +module.exports = { + 'auto-stats.org.cn': { + _name: '中国汽车工业协会统计信息网', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/routes/other#zhong-guo-qi-che-xie-hui-tong-ji-xin-xi-wang-fen-lei', + source: ['/:category'], + target: (params) => { + const category = params.category; + + return `/auto-stats${category ? `/${category.replace(/\.asp$/, '')}` : ''}`; + }, + }, + { + title: '信息快递', + docs: 'https://docs.rsshub.app/routes/other#zhong-guo-qi-che-xie-hui-tong-ji-xin-xi-wang-fen-lei', + source: ['/xxkd.asp'], + target: '/auto-stats/xxkd', + }, + { + title: '工作动态', + docs: 'https://docs.rsshub.app/routes/other#zhong-guo-qi-che-xie-hui-tong-ji-xin-xi-wang-fen-lei', + source: ['/gzdt.asp'], + target: '/auto-stats/gzdt', + }, + { + title: '专题分析', + docs: 'https://docs.rsshub.app/routes/other#zhong-guo-qi-che-xie-hui-tong-ji-xin-xi-wang-fen-lei', + source: ['/ztfx.asp'], + target: '/auto-stats/ztfx', + }, + ], + }, +}; diff --git a/lib/v2/auto-stats/router.js b/lib/v2/auto-stats/router.js new file mode 100644 index 00000000000000..19b84c05d31da0 --- /dev/null +++ b/lib/v2/auto-stats/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:category?', require('./')); +}; diff --git a/website/docs/routes/other.mdx b/website/docs/routes/other.mdx index 272f4ff7d723cd..e80eb5ddfe7783 100644 --- a/website/docs/routes/other.mdx +++ b/website/docs/routes/other.mdx @@ -1047,6 +1047,18 @@ Specify options (in the format of query string) in parameter `routeParams` param | 299 | 2143 | +## 中国汽车工业协会统计信息网 + +### 分类 + + + +| 信息快递 | 工作动态 | 专题分析 | +| -------- | -------- | -------- | +| xxkd | gzdt | ztfx | + + + ## 中国期货业协会 {#zhong-guo-qi-huo-ye-xie-hui} ### 分析师园地 {#zhong-guo-qi-huo-ye-xie-hui-fen-xi-shi-yuan-di}