From a0eb4e0c6705dbf5620f962868cb2eaf99b922e8 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 23 Sep 2022 02:24:22 +0800 Subject: [PATCH] feat(route): gelonghui (#10861) --- docs/finance.md | 16 +++++++++--- lib/router.js | 8 +++--- lib/routes/gelonghui/keyword.js | 36 -------------------------- lib/routes/gelonghui/subject.js | 42 ------------------------------ lib/routes/gelonghui/user.js | 46 --------------------------------- lib/v2/gelonghui/home.js | 31 ++++++++++++++++++++++ lib/v2/gelonghui/keyword.js | 34 ++++++++++++++++++++++++ lib/v2/gelonghui/maintainer.js | 6 +++++ lib/v2/gelonghui/radar.js | 31 ++++++++++++++++++++++ lib/v2/gelonghui/router.js | 6 +++++ lib/v2/gelonghui/subject.js | 36 ++++++++++++++++++++++++++ lib/v2/gelonghui/user.js | 33 +++++++++++++++++++++++ lib/v2/gelonghui/utils.js | 21 +++++++++++++++ 13 files changed, 215 insertions(+), 131 deletions(-) delete mode 100644 lib/routes/gelonghui/keyword.js delete mode 100644 lib/routes/gelonghui/subject.js delete mode 100644 lib/routes/gelonghui/user.js create mode 100644 lib/v2/gelonghui/home.js create mode 100644 lib/v2/gelonghui/keyword.js create mode 100644 lib/v2/gelonghui/maintainer.js create mode 100644 lib/v2/gelonghui/radar.js create mode 100644 lib/v2/gelonghui/router.js create mode 100644 lib/v2/gelonghui/subject.js create mode 100644 lib/v2/gelonghui/user.js create mode 100644 lib/v2/gelonghui/utils.js diff --git a/docs/finance.md b/docs/finance.md index ddfdd166d9..d1bb33e27d 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -244,17 +244,27 @@ TokenInsight 官方亦有提供 RSS,可参考 + +| 推荐 | 股票 | 基金 | 新股 | 研报 | +| ------------- | ----- | ---- | --------- | -------- | +| web_home_page | stock | fund | new_stock | research | + + + ### 用户文章 - + ### 主题文章 - + ### 搜索关键字 - + ## 国家金融与发展实验室 diff --git a/lib/router.js b/lib/router.js index 01f436725f..17ed8825e6 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2968,10 +2968,10 @@ router.get('/dsb/area/:area', lazyloadRouteHandler('./routes/dsb/area')); // 靠谱新闻 router.get('/kaopunews/:language?', lazyloadRouteHandler('./routes/kaopunews')); -// 格隆汇 -router.get('/gelonghui/user/:id', lazyloadRouteHandler('./routes/gelonghui/user')); -router.get('/gelonghui/subject/:id', lazyloadRouteHandler('./routes/gelonghui/subject')); -router.get('/gelonghui/keyword/:keyword', lazyloadRouteHandler('./routes/gelonghui/keyword')); +// 格隆汇 migrated to v2 +// router.get('/gelonghui/user/:id', lazyloadRouteHandler('./routes/gelonghui/user')); +// router.get('/gelonghui/subject/:id', lazyloadRouteHandler('./routes/gelonghui/subject')); +// router.get('/gelonghui/keyword/:keyword', lazyloadRouteHandler('./routes/gelonghui/keyword')); // 光谷社区 router.get('/guanggoo/:category?', lazyloadRouteHandler('./routes/guanggoo/index')); diff --git a/lib/routes/gelonghui/keyword.js b/lib/routes/gelonghui/keyword.js deleted file mode 100644 index 92a43b9b0e..0000000000 --- a/lib/routes/gelonghui/keyword.js +++ /dev/null @@ -1,36 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const currentUrl = `https://www.gelonghui.com/api/search/post?keyword=${ctx.params.keyword}&count=20&page=1&type=all`; - const response = await got({ - method: 'get', - url: currentUrl, - }); - const $ = cheerio.load(response.data); - - const list = response.data.result.postList.map((item) => ({ - title: item.title, - link: `https://www.gelonghui.com/p/${item.id}`, - pubDate: new Date(item.createDate).toUTCString(), - })); - - const items = await Promise.all( - list.map((item) => - ctx.cache.tryGet(item.link, async () => { - const res = await got({ method: 'get', url: item.link }); - const content = cheerio.load(res.data); - - item.description = content('article.article-with-html').html(); - return item; - }) - ) - ); - - ctx.state.data = { - title: `格隆汇 - 关键词 “${ctx.params.keyword}” 的文章`, - link: currentUrl, - item: items, - description: $('p.search-number').text(), - }; -}; diff --git a/lib/routes/gelonghui/subject.js b/lib/routes/gelonghui/subject.js deleted file mode 100644 index c763d8704b..0000000000 --- a/lib/routes/gelonghui/subject.js +++ /dev/null @@ -1,42 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const currentUrl = `https://www.gelonghui.com/subject/${ctx.params.id}`; - const response = await got({ - method: 'get', - url: currentUrl, - }); - const $ = cheerio.load(response.data); - const list = $('#subject-article ul li') - .slice(0, 15) - .map((_, item) => { - item = $(item); - const h = item.find('h2').length === 0 ? item.find('p') : item.find('h2'); - return { - title: h.text(), - link: h.parent().attr('href'), - pubDate: new Date(item.find('span').eq(2).text()).toUTCString(), - }; - }) - .get(); - - const items = await Promise.all( - list.map((item) => - ctx.cache.tryGet(item.link, async () => { - const res = await got({ method: 'get', url: item.link }); - const content = cheerio.load(res.data); - - item.description = content('article.article-with-html').html(); - return item; - }) - ) - ); - - ctx.state.data = { - title: `格隆汇 - 主题 ${$('span.user-nick').text()} 的文章`, - link: currentUrl, - item: items, - description: $('div.user-name').parent().children('p').text(), - }; -}; diff --git a/lib/routes/gelonghui/user.js b/lib/routes/gelonghui/user.js deleted file mode 100644 index b90669ccf3..0000000000 --- a/lib/routes/gelonghui/user.js +++ /dev/null @@ -1,46 +0,0 @@ -const url = require('url'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const currentUrl = `https://www.gelonghui.com/user/${ctx.params.id}?type=article`; - const response = await got({ - method: 'get', - url: currentUrl, - }); - const $ = cheerio.load(response.data); - const list = $('section.item') - .slice(0, 15) - .map((_, item) => { - item = $(item); - const h = item.find('h2'); - const pubDate = item.find('p').text(); - return { - title: h.text(), - link: url.resolve(`https://www.gelonghui.com`, h.parent().attr('href')), - pubDate: new Date( - pubDate.substr(pubDate.length - 1, 1) !== '分' ? new Date().getFullYear() + '-' + pubDate : pubDate.replace('年', '-').replace('月', '-').replace('日', ' ').replace('时', ':').replace('分', '') - ).toUTCString(), - }; - }) - .get(); - - const items = await Promise.all( - list.map((item) => - ctx.cache.tryGet(item.link, async () => { - const res = await got({ method: 'get', url: item.link }); - const content = cheerio.load(res.data); - - item.description = content('article.article-with-html').html(); - return item; - }) - ) - ); - - ctx.state.data = { - title: `格隆汇 - 用户 ${$('p.nick').text()} 的文章`, - link: currentUrl, - item: items, - description: $('div.val').text(), - }; -}; diff --git a/lib/v2/gelonghui/home.js b/lib/v2/gelonghui/home.js new file mode 100644 index 0000000000..f6371a5387 --- /dev/null +++ b/lib/v2/gelonghui/home.js @@ -0,0 +1,31 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const { parseItem } = require('./utils'); + +module.exports = async (ctx) => { + const { tag = 'web_home_page' } = ctx.params; + const apiUrl = `https://www.gelonghui.com/api/channels/${tag}/articles/v8`; + const { data } = await got(apiUrl); + + const list = data.result.map((article) => { + article = article.data; + return { + title: article.title, + description: article.summary, + link: article.link, + author: article.nick, + category: article.source, + pubDate: parseDate(article.timestamp, 'X'), + }; + }); + + const items = await Promise.all(list.map((item) => parseItem(item, ctx.cache.tryGet))); + + ctx.state.data = { + title: '格隆汇-财经资讯动态-股市行情', + description: '格隆汇为中国投资者出海投资及中国公司出海融资,提供海外投资,港股开户行情,科创板股票发行数据、资讯、研究、交易等一站式服务,目前业务范围主要涉及港股与美股两大市场,未来将陆续开通台湾、日本、印度、欧洲等市场.', + image: 'https://cdn.gelonghui.com/static/web/www.ico.la.ico', + link: 'https://www.gelonghui.com', + item: items, + }; +}; diff --git a/lib/v2/gelonghui/keyword.js b/lib/v2/gelonghui/keyword.js new file mode 100644 index 0000000000..f6e7bf973e --- /dev/null +++ b/lib/v2/gelonghui/keyword.js @@ -0,0 +1,34 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const { parseItem } = require('./utils'); + +module.exports = async (ctx) => { + const { keyword } = ctx.params; + const currentUrl = `https://www.gelonghui.com/api/post/search/v4`; + const { data } = await got(currentUrl, { + searchParams: { + keyword, + isVipArticle: false, + count: ctx.query.limit ? Number(ctx.query.limit) : 20, + page: 1, + searchArea: 'all', + }, + }); + + const list = data.result.map((item) => ({ + title: item.title, + description: item.summary, + link: item.link, + author: item.source, + pubDate: parseDate(item.timestamp, 'X'), + })); + + const items = await Promise.all(list.map((item) => parseItem(item, ctx.cache.tryGet))); + + ctx.state.data = { + title: `格隆汇 - 关键词 “${keyword}” 的文章`, + link: currentUrl, + item: items, + description: `找到关于 “ ${keyword} ”的文章,共${data.totalCount}个结果`, + }; +}; diff --git a/lib/v2/gelonghui/maintainer.js b/lib/v2/gelonghui/maintainer.js new file mode 100644 index 0000000000..b4e31062e8 --- /dev/null +++ b/lib/v2/gelonghui/maintainer.js @@ -0,0 +1,6 @@ +module.exports = { + '/home/:tag?': ['TonyRL'], + '/keyword/:keyword': ['nczitzk'], + '/subject/:id': ['nczitzk'], + '/user/:id': ['nczitzk'], +}; diff --git a/lib/v2/gelonghui/radar.js b/lib/v2/gelonghui/radar.js new file mode 100644 index 0000000000..6519a1f06b --- /dev/null +++ b/lib/v2/gelonghui/radar.js @@ -0,0 +1,31 @@ +module.exports = { + 'gelonghui.com': { + _name: '格隆汇', + '.': [ + { + title: '首页', + docs: 'https://docs.rsshub.app/finance.html#ge-long-hui', + source: ['/tag/:tag', '/'], + target: (params) => `/gelonghui/home${params.tag ? `/${params.tag}` : ''}`, + }, + { + title: '搜索关键字', + docs: 'https://docs.rsshub.app/finance.html#ge-long-hui', + source: ['/search'], + target: (_, url) => `/gelonghui/keyword/${new URL(url).searchParams.get('keyword')}`, + }, + { + title: '主题文章', + docs: 'https://docs.rsshub.app/finance.html#ge-long-hui', + source: ['/subject/:id'], + target: '/gelonghui/subject/:id', + }, + { + title: '用户文章', + docs: 'https://docs.rsshub.app/finance.html#ge-long-hui', + source: ['/user/:id'], + target: '/gelonghui/user/:id', + }, + ], + }, +}; diff --git a/lib/v2/gelonghui/router.js b/lib/v2/gelonghui/router.js new file mode 100644 index 0000000000..6517ad9596 --- /dev/null +++ b/lib/v2/gelonghui/router.js @@ -0,0 +1,6 @@ +module.exports = (router) => { + router.get('/home/:tag?', require('./home')); + router.get('/keyword/:keyword', require('./keyword')); + router.get('/subject/:id', require('./subject')); + router.get('/user/:id', require('./user')); +}; diff --git a/lib/v2/gelonghui/subject.js b/lib/v2/gelonghui/subject.js new file mode 100644 index 0000000000..5d5b0601ad --- /dev/null +++ b/lib/v2/gelonghui/subject.js @@ -0,0 +1,36 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const { parseItem } = require('./utils'); + +module.exports = async (ctx) => { + const { id } = ctx.params; + const apiUrl = `https://www.gelonghui.com/api/subjects/${id}/contents`; + const pageUrl = `https://www.gelonghui.com/subject/${id}`; + const { data: response } = await got(pageUrl); + const { data } = await got(apiUrl, { + searchParams: { + isChoice: false, + }, + }); + + const $ = cheerio.load(response); + + const list = data.result.map((item) => ({ + title: item.title, + description: item.summary, + link: item.link, + author: item.source, + pubDate: parseDate(item.timestamp, 'X'), + })); + + const items = await Promise.all(list.map((item) => parseItem(item, ctx.cache.tryGet))); + + ctx.state.data = { + title: `格隆汇 - 主题 ${$('span.user-nick').text()} 的文章`, + description: $('div.user-name').parent().children('p').text(), + image: $('.subject-list-title').find('img').attr('data-src'), + link: `https://www.gelonghui.com/subject/${id}`, + item: items, + }; +}; diff --git a/lib/v2/gelonghui/user.js b/lib/v2/gelonghui/user.js new file mode 100644 index 0000000000..be3fa41c41 --- /dev/null +++ b/lib/v2/gelonghui/user.js @@ -0,0 +1,33 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const { parseItem } = require('./utils'); + +module.exports = async (ctx) => { + const { id: userId } = ctx.params; + const currentUrl = 'https://www.gelonghui.com/api/community/dynamic/my-dynamics/v2'; + const { data } = await got(currentUrl, { + searchParams: { + article: true, + userId, + count: ctx.query.limit ? Number(ctx.query.limit) : 15, + }, + }); + + const list = data.result.map((item) => ({ + title: item.title, + link: item.route, + description: item.content, + author: item.user.nick, + pubDate: parseDate(item.createTimestamp, 'X'), + })); + + const items = await Promise.all(list.map((item) => parseItem(item, ctx.cache.tryGet))); + + ctx.state.data = { + title: `格隆汇 - 用户 ${data.result[0].user.nick} 的文章`, + description: data.result.find((i) => i.user).user.brief, + image: data.result.find((i) => i.user).user.avatar.split('@')[0], + link: data.result.find((i) => i.user).user.route.replace('https://m.gelonghui.com', 'https://www.gelonghui.com'), + item: items, + }; +}; diff --git a/lib/v2/gelonghui/utils.js b/lib/v2/gelonghui/utils.js new file mode 100644 index 0000000000..5e621b5daa --- /dev/null +++ b/lib/v2/gelonghui/utils.js @@ -0,0 +1,21 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const parseItem = (item, tryGet) => + tryGet(item.link, async () => { + const { data: res } = await got(item.link); + const $ = cheerio.load(res); + if (item.link.startsWith('https://www.gelonghui.com/live/')) { + item.title = $('.type-name').next().text().trim(); + item.description = $('.dtb-content').html(); + } else { + // article + item.title = $('.article-title').text().trim(); + item.description = $('.article-summary').html() + $('article.article-with-html').html(); + } + return item; + }); + +module.exports = { + parseItem, +};