From 30e99fdd840bcc348c25469a625fed25aea74a8d Mon Sep 17 00:00:00 2001 From: drgnchan <40224023+drgnchan@users.noreply.github.com> Date: Sat, 15 Apr 2023 00:30:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E4=B8=9C=E6=96=B9=E8=B4=A2?= =?UTF-8?q?=E5=AF=8C=E7=BD=91=E6=90=9C=E7=B4=A2=E5=85=B3=E9=94=AE=E8=AF=8D?= =?UTF-8?q?=20(#12309)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat[route]: 东方财富网搜索关键词 * refactor: 设置描述内容 * fix: duplicate title * refactor: add doc * refactor: use api instead of puppeteer * refactor: polish code --------- --- docs/finance.md | 4 +++ lib/v2/eastmoney/maintainer.js | 1 + lib/v2/eastmoney/radar.js | 8 +++++ lib/v2/eastmoney/router.js | 1 + lib/v2/eastmoney/search/index.js | 55 ++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 lib/v2/eastmoney/search/index.js diff --git a/docs/finance.md b/docs/finance.md index 2dbd225511..9fd587df85 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -258,6 +258,10 @@ TokenInsight 官方亦有提供 RSS,可参考 +### 搜索 + + + ## 法布财经 ### 新闻 diff --git a/lib/v2/eastmoney/maintainer.js b/lib/v2/eastmoney/maintainer.js index abe1224b72..a1e0043522 100644 --- a/lib/v2/eastmoney/maintainer.js +++ b/lib/v2/eastmoney/maintainer.js @@ -1,3 +1,4 @@ module.exports = { '/ttjj/user/:uid': ['zidekuls'], + '/search/:keyword': ['drgnchan'], }; diff --git a/lib/v2/eastmoney/radar.js b/lib/v2/eastmoney/radar.js index f738351e2a..a7ff7f8ee7 100644 --- a/lib/v2/eastmoney/radar.js +++ b/lib/v2/eastmoney/radar.js @@ -9,5 +9,13 @@ module.exports = { target: (_param, url) => `/eastmoney/ttjj/user/${new URL(url).searchParams.get('userid')}`, }, ], + so: [ + { + title: '搜索', + docs: 'https://docs.rsshub.app/finance.html#dong-fang-cai-fu', + source: ['/News/s'], + target: (_param, url) => `/eastmoney/search/${new URL(url).searchParams.get('KeyWord')}`, + }, + ], }, }; diff --git a/lib/v2/eastmoney/router.js b/lib/v2/eastmoney/router.js index 1bd4ddbd7d..8d86a8aae1 100644 --- a/lib/v2/eastmoney/router.js +++ b/lib/v2/eastmoney/router.js @@ -1,3 +1,4 @@ module.exports = (router) => { router.get('/ttjj/user/:uid', require('./ttjj/user')); + router.get('/search/:keyword', require('./search/index')); }; diff --git a/lib/v2/eastmoney/search/index.js b/lib/v2/eastmoney/search/index.js new file mode 100644 index 0000000000..14116f2eee --- /dev/null +++ b/lib/v2/eastmoney/search/index.js @@ -0,0 +1,55 @@ +const { parseDate } = require('@/utils/parse-date'); +const got = require('@/utils/got'); +const timezone = require('@/utils/timezone'); + +module.exports = async (ctx) => { + const keyword = ctx.params.keyword; + const link = `https://so.eastmoney.com/News/s?KeyWord=${keyword}`; + const body = { + uid: '', + keyword, + type: ['cmsArticleWebOld'], + client: 'web', + clientType: 'web', + clientVersion: 'curr', + params: { + cmsArticleWebOld: { + searchScope: 'default', + sort: 'default', + pageIndex: 1, + pageSize: 10, + preTag: '', + postTag: '', + }, + }, + }; + const cb = `jQuery${('3.5.1' + Math.random()).replace(/\D/g, '')}_${Date.now()}`; + + const url = `https://search-api-web.eastmoney.com/search/jsonp`; + + const response = await got(url, { + searchParams: { + cb, + param: JSON.stringify(body), + }, + }); + const data = response.data; + + const extractedText = data.match(/jQuery\d+_\d+\((.*)\)/)[1]; + + const obj = JSON.parse(extractedText); + const arr = obj.result.cmsArticleWebOld; + + const items = arr.map((item) => ({ + title: item.title, + description: item.content, + pubDate: timezone(parseDate(item.date), 8), + link: item.url, + author: item.mediaName, + })); + ctx.state.data = { + title: `东方财富网 - 搜索'${keyword}'`, + link, + item: items, + }; +};