From fcee9cd197cebe565ca5b420baff1f6d30a701ad Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 23 Jan 2022 03:01:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=B7=B4=E4=BC=A6?= =?UTF-8?q?=E5=91=A8=E5=88=8A=E4=B8=AD=E6=96=87=E7=89=88=20(#8675)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/finance.md | 14 +++++++ lib/v2/barronschina/index.js | 70 +++++++++++++++++++++++++++++++ lib/v2/barronschina/maintainer.js | 3 ++ lib/v2/barronschina/radar.js | 13 ++++++ lib/v2/barronschina/router.js | 3 ++ 5 files changed, 103 insertions(+) create mode 100644 lib/v2/barronschina/index.js create mode 100644 lib/v2/barronschina/maintainer.js create mode 100644 lib/v2/barronschina/radar.js create mode 100644 lib/v2/barronschina/router.js diff --git a/docs/finance.md b/docs/finance.md index c2c5e4bb1..7d27c463d 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -38,6 +38,20 @@ pageClass: routes | -------- | -------- | -------- | -------- | -------- | -------- | -------- | ---------- | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | +## 巴伦周刊中文版 + +### 栏目 + + + +::: tip 提示 + +栏目 id 留空则返回快讯,在对应页地址栏 `columnId=` 后可以看到。 + +::: + + + ## 北京证券交易所 ### 栏目 diff --git a/lib/v2/barronschina/index.js b/lib/v2/barronschina/index.js new file mode 100644 index 000000000..691355263 --- /dev/null +++ b/lib/v2/barronschina/index.js @@ -0,0 +1,70 @@ +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 id = ctx.params.id ?? ''; + + const rootUrl = 'http://www.barronschina.com.cn'; + const currentUrl = `${rootUrl}/index/${id ? `column/article?columnId=${id}` : 'shortNews'}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const items = id + ? await Promise.all( + $('.title') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.find('.title').text(), + link: `${rootUrl}${item.parent().attr('href')}`, + }; + }) + .map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.description = content('.cont_main').html(); + item.pubDate = timezone(parseDate(content('.timeTag').text()), +8); + + return item; + }) + ) + ) + : $('dd') + .toArray() + .map((item) => { + item = $(item); + + const title = item.find('strong').text(); + item.find('strong').remove(); + + const description = item.find('.short').html(); + item.find('.short').remove(); + + return { + title, + description, + link: currentUrl, + pubDate: timezone(parseDate(`${item.parent().find('dt').text()} ${item.text()}`), +8), + }; + }); + + ctx.state.data = { + title: $('title').text().split(',')[0], + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/barronschina/maintainer.js b/lib/v2/barronschina/maintainer.js new file mode 100644 index 000000000..77e7f46e2 --- /dev/null +++ b/lib/v2/barronschina/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:id?': ['nczitzk'], +}; diff --git a/lib/v2/barronschina/radar.js b/lib/v2/barronschina/radar.js new file mode 100644 index 000000000..3771ea072 --- /dev/null +++ b/lib/v2/barronschina/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'barronschina.com.cn': { + _name: '巴伦周刊中文版', + '.': [ + { + title: '栏目', + docs: 'https://docs.rsshub.app/finance.html#ba-lun-zhou-kan-zhong-wen-ban-lan-mu', + source: ['/'], + target: '/barronschina/:category?', + }, + ], + }, +}; diff --git a/lib/v2/barronschina/router.js b/lib/v2/barronschina/router.js new file mode 100644 index 000000000..c7491b29f --- /dev/null +++ b/lib/v2/barronschina/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:id?', require('./index')); +};