From 627ce33803597c015344efceb60332229a1f31dd Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Fri, 30 Sep 2022 10:39:00 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=99=BA=E9=80=9A?= =?UTF-8?q?=E8=B4=A2=E7=BB=8F=20(#10961)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 智通财经 * fix: add vip and telegram digest --- docs/finance.md | 25 ++++ lib/v2/zhitongcaijing/index.js | 118 ++++++++++++++++++ lib/v2/zhitongcaijing/maintainer.js | 3 + lib/v2/zhitongcaijing/radar.js | 17 +++ lib/v2/zhitongcaijing/router.js | 3 + .../zhitongcaijing/templates/description.art | 6 + 6 files changed, 172 insertions(+) create mode 100644 lib/v2/zhitongcaijing/index.js create mode 100644 lib/v2/zhitongcaijing/maintainer.js create mode 100644 lib/v2/zhitongcaijing/radar.js create mode 100644 lib/v2/zhitongcaijing/router.js create mode 100644 lib/v2/zhitongcaijing/templates/description.art diff --git a/docs/finance.md b/docs/finance.md index daa1705f4..7925dc4fb 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -627,6 +627,31 @@ TokenInsight 官方亦有提供 RSS,可参考 +## 智通财经网 + +### 推荐 + + + +| id | 栏目 | +| ------------ | --- | +| recommend | 推荐 | +| hkstock | 港股 | +| meigu | 美股 | +| agu | 沪深 | +| ct | 创投 | +| esg | ESG | +| aqs | 券商 | +| ajj | 基金 | +| focus | 要闻 | +| announcement | 公告 | +| research | 研究 | +| shares | 新股 | +| bazaar | 市场 | +| company | 公司 | + + + ## 中国人民银行 ### 沟通交流 diff --git a/lib/v2/zhitongcaijing/index.js b/lib/v2/zhitongcaijing/index.js new file mode 100644 index 000000000..26d9071ed --- /dev/null +++ b/lib/v2/zhitongcaijing/index.js @@ -0,0 +1,118 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +const ids = { + recommend: { + url: 'content/recommend', + title: '推荐', + }, + hkstock: { + url: 'content/hkstock', + title: '港股', + }, + meigu: { + url: 'content/meigu', + title: '美股', + }, + agu: { + url: 'content/agu', + title: '沪深', + }, + ct: { + url: 'content/ct', + title: '创投', + }, + esg: { + url: 'content/esg', + title: 'ESG', + }, + aqs: { + url: 'content/aqs', + title: '券商', + }, + ajj: { + url: 'content/ajj', + title: '基金', + }, + focus: { + url: 'focus', + title: '要闻', + }, + announcement: { + url: 'announcement', + title: '公告', + }, + research: { + url: 'research', + title: '研究', + }, + shares: { + url: 'shares', + title: '新股', + }, + bazaar: { + url: 'bazaar', + title: '市场', + }, + company: { + url: 'company', + title: '公司', + }, +}; + +module.exports = async (ctx) => { + const id = ctx.params.id ?? 'recommend'; + const category = ctx.params.category ?? ''; + + const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 20; + + const rootUrl = 'https://www.zhitongcaijing.com'; + const currentUrl = `${rootUrl}/${ids[id].url}.html${category === '' ? '' : `?category_key=${category}`}`; + const apiUrl = `${rootUrl}/${ids[id].url}.html?data_type=1&page=1${category === '' ? '' : `&category_key=${category}`}`; + + const response = await got({ + method: 'get', + url: apiUrl, + }); + + let items = response.data.data.slice(0, limit).map((item) => ({ + title: item.title, + link: `${rootUrl}${item.url}`, + description: item.digest, + author: item.author_info.author_name, + pubDate: parseDate((item.create_time ?? parseInt(item.original_time)) * 1000), + category: (item.keywords?.split(',') ?? []).concat([item.category_name ?? item.type_tag]), + })); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + content('#subscribe-vip-box').remove(); + content('#news-content').remove(); + + item.description = art(path.join(__dirname, 'templates/description.art'), { + digest: content('.digetst-box').html() || content('.telegram-origin-contentn').html(), + description: content('.news-body-content').html(), + }); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `智通财经 - ${ids[id].title}`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/zhitongcaijing/maintainer.js b/lib/v2/zhitongcaijing/maintainer.js new file mode 100644 index 000000000..db32d54ac --- /dev/null +++ b/lib/v2/zhitongcaijing/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:id?/:category?': ['nczitzk'], +}; diff --git a/lib/v2/zhitongcaijing/radar.js b/lib/v2/zhitongcaijing/radar.js new file mode 100644 index 000000000..51a882948 --- /dev/null +++ b/lib/v2/zhitongcaijing/radar.js @@ -0,0 +1,17 @@ +module.exports = { + 'zhitongcaijing.com': { + _name: '智通财经', + '.': [ + { + title: '资讯', + docs: 'https://docs.rsshub.app/finance.html#zhi-tong-cai-jing-zi-xun', + source: ['/:category', '/'], + target: (params, url) => { + const id = new URL(url).toString().match(/\/(\w+)\.html/)[1]; + const category = new URL(url).searchParams.get('category_key'); + return `/zhitongcaijing/${id}${category ? `/${category}` : ''}`; + }, + }, + ], + }, +}; diff --git a/lib/v2/zhitongcaijing/router.js b/lib/v2/zhitongcaijing/router.js new file mode 100644 index 000000000..ea2152ae0 --- /dev/null +++ b/lib/v2/zhitongcaijing/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:id?/:category?', require('./index')); +}; diff --git a/lib/v2/zhitongcaijing/templates/description.art b/lib/v2/zhitongcaijing/templates/description.art new file mode 100644 index 000000000..715af125f --- /dev/null +++ b/lib/v2/zhitongcaijing/templates/description.art @@ -0,0 +1,6 @@ +{{ if digest }} +{{@ digest }} +{{ /if }} +{{ if description }} +{{@ description }} +{{ /if }} \ No newline at end of file