From 5622641efa053ac971592a36be0db79cb4c7108e Mon Sep 17 00:00:00 2001 From: kdan Date: Sat, 16 Apr 2022 23:30:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E9=A6=96=E5=B8=AD=E7=BB=8F?= =?UTF-8?q?=E6=B5=8E=E5=AD=A6=E5=AE=B6=E8=AE=BA=E5=9D=9B=20(#9550)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add(route): 首席经济学家论坛 * fix(route) : merge from FledgeXu * fix(route) : merge from FledgeXu * (fix) typo * feat(route): remove radar from radar-rules.js * Update lib/v2/chinacef/hot.js Co-authored-by: Tony * Update lib/v2/chinacef/router.js Co-authored-by: Tony * Update lib/v2/chinacef/maintainer.js Co-authored-by: Tony * Update lib/v2/chinacef/experts.js Co-authored-by: Tony * Update lib/v2/chinacef/experts.js Co-authored-by: Tony * Update hot.js * Update experts.js Co-authored-by: linkai Co-authored-by: Tony --- docs/finance.md | 14 +++++ lib/v2/chinacef/experts.js | 52 ++++++++++++++++++ lib/v2/chinacef/hot.js | 53 +++++++++++++++++++ lib/v2/chinacef/maintainer.js | 4 +- lib/v2/chinacef/radar.js | 12 +++++ lib/v2/chinacef/router.js | 2 + .../chinacef/templates/work_description.art | 1 + 7 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 lib/v2/chinacef/experts.js create mode 100644 lib/v2/chinacef/hot.js create mode 100644 lib/v2/chinacef/templates/work_description.art diff --git a/docs/finance.md b/docs/finance.md index 5ca9d2c5e..c2064aab9 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -243,6 +243,20 @@ pageClass: routes +### 专家 + + + +| 李迅雷 | 夏斌 | +| --- | -- | +| 17 | 35 | + + + +### 金融热点 + + + ## 淘股吧股票论坛 ### 论坛总版 diff --git a/lib/v2/chinacef/experts.js b/lib/v2/chinacef/experts.js new file mode 100644 index 000000000..2e90e1785 --- /dev/null +++ b/lib/v2/chinacef/experts.js @@ -0,0 +1,52 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { art } = require('@/utils/render'); +const path = require('path'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const response = await got(`http://www.chinacef.cn/index.php/experts/zjmain/experts_id/${ctx.params.experts_id}`); + + const data = response.data; + + const $ = cheerio.load(data); + + const domArray = $('div[class^="leftnews"]'); + const itemAuthor = $('div[class=right515name] h3').text().trim(); + const siteLink = 'http://www.chinacef.cn'; + const rssTitle = $('title').text().trim(); + + const itemArray = await Promise.all( + domArray + .filter((index, item) => undefined !== $(item).find('h2 > a').attr('href')) + .map(async (index, item) => { + item = $(item); + const itemLink = siteLink + item.find('h2 > a').attr('href'); + const detail = await ctx.cache.tryGet(itemLink, async () => { + const result = await got.get(itemLink); + const $ = cheerio.load(result.data); + const description = art(path.join(__dirname, 'templates/work_description.art'), { + desc: $('.newsmaintext').first().html().trim(), + }); + return { + title: $('.contenttitle').first().html().trim(), + article: description, + }; + }); + + return { + title: detail.title, + description: detail.article, + link: itemLink, + pubDate: parseDate(item.find('span').first().text(), 'YYYY-MM-DD'), + author: itemAuthor, + }; + }) + ); + + ctx.state.data = { + title: rssTitle, + link: siteLink, + item: itemArray, + }; +}; diff --git a/lib/v2/chinacef/hot.js b/lib/v2/chinacef/hot.js new file mode 100644 index 000000000..bd0f50526 --- /dev/null +++ b/lib/v2/chinacef/hot.js @@ -0,0 +1,53 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { art } = require('@/utils/render'); +const path = require('path'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const response = await got.get('http://www.chinacef.cn/index.php/index/index'); + + const data = response.data; + + const $ = cheerio.load(data); + + const domArray = $('#boardright ul'); + const siteLink = 'http://www.chinacef.cn'; + const rssTitle = '金融热点 - 首席经济学家论坛'; + + const itemArray = await Promise.all( + domArray + .map(async (index, item) => { + item = $(item); + const itemLink = siteLink + item.find('li a').attr('href'); + const detail = await ctx.cache.tryGet(itemLink, async () => { + const result = await got.get(itemLink); + const $ = cheerio.load(result.data); + const description = art(path.join(__dirname, 'templates/work_description.art'), { + desc: $('.newsmaintext').first().html().trim(), + }); + return { + title: $('.contenttitle').first().html().trim(), + author: $('.zzinfo').find('h2').first().text().trim(), + pubDate: parseDate($('.divwidth').text().trim().split(' ')[3], 'YYYY-MM-DD'), + article: description, + }; + }); + + return { + title: detail.title, + description: detail.article, + link: itemLink, + pubDate: detail.pubDate, + author: detail.author, + }; + }) + .get() + ); + + ctx.state.data = { + title: rssTitle, + link: siteLink, + item: itemArray, + }; +}; diff --git a/lib/v2/chinacef/maintainer.js b/lib/v2/chinacef/maintainer.js index ea25bbdb5..d2813e175 100644 --- a/lib/v2/chinacef/maintainer.js +++ b/lib/v2/chinacef/maintainer.js @@ -1,3 +1,5 @@ module.exports = { - '/chinacef': ['FledgeXu'], + '/': ['FledgeXu'], + '/:experts_id': ['kdanfly'], + '/portal/hot': ['kdanfly'], }; diff --git a/lib/v2/chinacef/radar.js b/lib/v2/chinacef/radar.js index 6a390fdcb..d9e913b28 100644 --- a/lib/v2/chinacef/radar.js +++ b/lib/v2/chinacef/radar.js @@ -8,6 +8,18 @@ module.exports = { source: ['/'], target: '/chinacef', }, + { + title: '专家文章', + docs: 'https://docs.rsshub.app/finance.html#shou-xi-jing-ji-xue-jia-lun-tan-zhuan-jia', + source: ['/index.php/experts/zjmain/experts_id/:experts_id'], + target: '/chinacef/:experts_id', + }, + { + title: '金融热点', + docs: 'https://docs.rsshub.app/finance.html#shou-xi-jing-ji-xue-jia-lun-tan-jin-rong-re-dian', + source: ['/index.php/index/index'], + target: '/chinacef/portal/hot', + }, ], }, }; diff --git a/lib/v2/chinacef/router.js b/lib/v2/chinacef/router.js index 20c52b09d..6a78094f4 100644 --- a/lib/v2/chinacef/router.js +++ b/lib/v2/chinacef/router.js @@ -1,3 +1,5 @@ module.exports = function (router) { + router.get('/:experts_id', require('./experts')); + router.get('/portal/hot', require('./hot')); router.get('/', require('./index')); }; diff --git a/lib/v2/chinacef/templates/work_description.art b/lib/v2/chinacef/templates/work_description.art new file mode 100644 index 000000000..25baa934c --- /dev/null +++ b/lib/v2/chinacef/templates/work_description.art @@ -0,0 +1 @@ +
{{ desc }}