diff --git a/docs/finance.md b/docs/finance.md index 6d2b1a79ab..27440fb3d8 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -383,15 +383,21 @@ TokenInsight 官方亦有提供 RSS,可参考 -## 淘股吧股票论坛 +## 淘股吧 -### 论坛总版 +### 淘股论坛 - + + +| 淘股论坛 | 社区总版 | 精华加油 | 网友点赞 | +| ---- | ------- | ------- | ------- | +| bbs | zongban | jinghua | dianzan | + + ### 用户博客 - + ## 乌拉邦 diff --git a/lib/router.js b/lib/router.js index 5c325df355..45e807a1d4 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1386,8 +1386,8 @@ router.get('/blogs/wordpress/:domain/:https?', lazyloadRouteHandler('./routes/bl router.get('/xici/:id?', lazyloadRouteHandler('./routes/xici')); // 淘股吧论坛 -router.get('/taoguba/index', lazyloadRouteHandler('./routes/taoguba/index')); -router.get('/taoguba/user/:uid', lazyloadRouteHandler('./routes/taoguba/user')); +// router.get('/taoguba/index', lazyloadRouteHandler('./routes/taoguba/index')); +// router.get('/taoguba/user/:uid', lazyloadRouteHandler('./routes/taoguba/user')); // 今日热榜 router.get('/tophub/:id', lazyloadRouteHandler('./routes/tophub')); diff --git a/lib/routes/taoguba/index.js b/lib/routes/taoguba/index.js deleted file mode 100644 index d33b6cc054..0000000000 --- a/lib/routes/taoguba/index.js +++ /dev/null @@ -1,46 +0,0 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const url = `https://www.taoguba.com.cn/index`; - - const res = await got.get(url); - const $ = cheerio.load(res.data); - const list = $('.p_list01').get(); - - const out = await Promise.all( - list.slice(0, 5).map(async (item) => { - const $ = cheerio.load(item); - const time = $('.pcdj06').text(); - const title = $('.pcdj02 a').attr('title'); - const partial = $('.pcdj02 a').attr('href'); - const address = `https://www.taoguba.com.cn/${partial}`; - const cache = await ctx.cache.get(address); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } - const res = await got.get(address); - const get = cheerio.load(res.data); - get('img').each((index, item) => { - item = get(item); - item.attr('src', item.attr('data-original')); - item.removeAttr('onload'); - }); - const contents = get('div#first.p_coten').html(); - const single = { - title, - pubDate: new Date(time).toUTCString(), - description: contents, - link: address, - guid: address, - }; - ctx.cache.set(address, JSON.stringify(single)); - return Promise.resolve(single); - }) - ); - ctx.state.data = { - title: '淘股吧股票论坛总版', - link: url, - item: out, - }; -}; diff --git a/lib/routes/taoguba/user.js b/lib/routes/taoguba/user.js deleted file mode 100644 index fa971da17c..0000000000 --- a/lib/routes/taoguba/user.js +++ /dev/null @@ -1,46 +0,0 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const url = `https://www.taoguba.com.cn/blog/${ctx.params.uid}`; - - const res = await got.get(url); - const $ = cheerio.load(res.data); - const list = $('.article_tittle').get(); - - const out = await Promise.all( - list.slice(0, 3).map(async (item) => { - const $ = cheerio.load(item); - const title = $('.tittle_data.left a').attr('title'); - const partial = $('.tittle_data.left a').attr('href'); - const address = `https://www.taoguba.com.cn/${partial}`; - const time = $('div.tittle_fbshijian.left').text(); - const cache = await ctx.cache.get(address); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } - const res = await got.get(address); - const get = cheerio.load(res.data); - get('img').each((index, item) => { - item = get(item); - item.attr('src', item.attr('data-original')); - item.removeAttr('onload'); - }); - const contents = get('div#first.p_coten').html(); - const single = { - title, - pubDate: new Date(time).toUTCString(), - description: contents, - link: address, - guid: address, - }; - ctx.cache.set(address, JSON.stringify(single)); - return Promise.resolve(single); - }) - ); - ctx.state.data = { - title: $('title').text(), - link: url, - item: out, - }; -}; diff --git a/lib/v2/taoguba/blog.js b/lib/v2/taoguba/blog.js new file mode 100644 index 0000000000..2bc9b2c89d --- /dev/null +++ b/lib/v2/taoguba/blog.js @@ -0,0 +1,59 @@ +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 = 'https://www.taoguba.com.cn'; + const currentUrl = `${rootUrl}/blog/${id}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('.tittle_data') + .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 50) + .toArray() + .map((item) => { + item = $(item); + + const a = item.find('a').first(); + + return { + title: a.text(), + link: `${rootUrl}/${a.attr('href')}`, + }; + }); + + 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('#videoImg').remove(); + + item.description = content('#first').html(); + item.author = content('.pcyclname').first().text(); + item.pubDate = timezone(parseDate(content('.pcyclspan').first().text()), +8); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `淘股吧 - ${$('meta[property="og:author"]').attr('content')}`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/taoguba/index.js b/lib/v2/taoguba/index.js new file mode 100644 index 0000000000..d3587e30b7 --- /dev/null +++ b/lib/v2/taoguba/index.js @@ -0,0 +1,67 @@ +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 category = ctx.params.category ?? 'zongban'; + + const rootUrl = 'https://www.taoguba.com.cn'; + const currentUrl = `${rootUrl}/${category}/`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('.p_list01, .blk, .cov') + .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 50) + .toArray() + .map((item) => { + item = $(item); + + const a = item.find('a').first(); + + return { + title: a.text(), + link: `${rootUrl}/${a.attr('href')}`, + }; + }); + + 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('#videoImg').remove(); + + item.description = content('#first').html(); + item.author = content('.pcyclname').first().text(); + item.pubDate = timezone(parseDate(content('.pcyclspan').first().text()), +8); + + return item; + }) + ) + ); + + let title = ''; + for (const t of $('.NewH_bot_title3 a').toArray()) { + if ($(t).attr('href') === currentUrl) { + title = $(t).text(); + break; + } + } + + ctx.state.data = { + title: `淘股吧 - ${title}`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/taoguba/maintainer.js b/lib/v2/taoguba/maintainer.js new file mode 100644 index 0000000000..21e596a7b9 --- /dev/null +++ b/lib/v2/taoguba/maintainer.js @@ -0,0 +1,6 @@ +module.exports = { + '/blog/:id': ['nczitzk'], + '/index': ['nczitzk'], + '/user/:id': ['nczitzk'], + '/:category?': ['nczitzk'], +}; diff --git a/lib/v2/taoguba/radar.js b/lib/v2/taoguba/radar.js new file mode 100644 index 0000000000..45ccfffaef --- /dev/null +++ b/lib/v2/taoguba/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'taoguba.com.cn': { + _name: '淘股吧', + '.': [ + { + title: '淘股论坛', + docs: 'https://docs.rsshub.app/finance.html#tao-gu-ba-tao-gu-lun-tan', + source: ['/:category', '/'], + target: '/taoguba/:category', + }, + { + title: '用户博客', + docs: 'https://docs.rsshub.app/finance.html#tao-gu-ba-yong-hu-bo-ke', + source: ['/blog/:id', '/'], + target: '/taoguba/blog/:id', + }, + ], + }, +}; diff --git a/lib/v2/taoguba/router.js b/lib/v2/taoguba/router.js new file mode 100644 index 0000000000..ca7b50fca4 --- /dev/null +++ b/lib/v2/taoguba/router.js @@ -0,0 +1,6 @@ +module.exports = function (router) { + router.get('/blog/:id', require('./blog')); + router.get('/index', require('./index')); + router.get('/user/:id', require('./blog')); + router.get('/:category?', require('./index')); +};