From 21115de374ea4a40c474b4ac68f2d1ecd9e2b927 Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 12 Dec 2022 15:24:46 -0400 Subject: [PATCH] feat(route): caijing (#11439) --- docs/finance.md | 6 +++++ lib/v2/caijing/maintainer.js | 3 +++ lib/v2/caijing/radar.js | 13 ++++++++++ lib/v2/caijing/roll.js | 46 ++++++++++++++++++++++++++++++++++++ lib/v2/caijing/router.js | 3 +++ 5 files changed, 71 insertions(+) create mode 100644 lib/v2/caijing/maintainer.js create mode 100644 lib/v2/caijing/radar.js create mode 100644 lib/v2/caijing/roll.js create mode 100644 lib/v2/caijing/router.js diff --git a/docs/finance.md b/docs/finance.md index b2d60331f..7dfae0225 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -208,6 +208,12 @@ TokenInsight 官方亦有提供 RSS,可参考 +## 财经网 + +### 滚动新闻 + + + ## 财联社 ### 电报 diff --git a/lib/v2/caijing/maintainer.js b/lib/v2/caijing/maintainer.js new file mode 100644 index 000000000..ee71eae61 --- /dev/null +++ b/lib/v2/caijing/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/roll': ['TonyRL'], +}; diff --git a/lib/v2/caijing/radar.js b/lib/v2/caijing/radar.js new file mode 100644 index 000000000..00f51989c --- /dev/null +++ b/lib/v2/caijing/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'caijing.com.cn': { + _name: '财经网', + roll: [ + { + title: '滚动新闻', + docs: 'https://docs.rsshub.app/finance.html#cai-jing-wang', + source: ['/index1.html', '/'], + target: '/caijing/roll', + }, + ], + }, +}; diff --git a/lib/v2/caijing/roll.js b/lib/v2/caijing/roll.js new file mode 100644 index 000000000..55611903d --- /dev/null +++ b/lib/v2/caijing/roll.js @@ -0,0 +1,46 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +module.exports = async (ctx) => { + const baseUrl = 'https://roll.caijing.com.cn'; + const response = await got(`${baseUrl}/ajax_lists.php`, { + searchParams: { + modelid: 0, + time: Math.random(), + }, + }); + + const list = response.data.map((item) => ({ + title: item.title, + link: item.url.replace('http://', 'https://'), + pubDate: timezone(parseDate(item.published, 'MM-DD HH:mm'), +8), + category: item.cat, + })); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const response = await got(item.link); + const $ = cheerio.load(response.data); + item.author = $('.editor').text().trim() || $('#editor_baidu').text().trim().replace(/[()]/g, ''); + item.description = $('.article-content').html(); + item.category = [ + item.category, + ...$('.news_keywords span') + .toArray() + .map((e) => $(e).text()), + ]; + return item; + }) + ) + ); + + ctx.state.data = { + title: '滚动新闻-财经网', + image: 'https://www.caijing.com.cn/favicon.ico', + link: response.url, + item: items, + }; +}; diff --git a/lib/v2/caijing/router.js b/lib/v2/caijing/router.js new file mode 100644 index 000000000..4e96fbdf3 --- /dev/null +++ b/lib/v2/caijing/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/roll', require('./roll')); +};