feat(route): add 淘股吧淘股论坛 (#10432)

This commit is contained in:
Ethan Shen
2022-08-10 22:21:09 +08:00
committed by GitHub
parent b39ee6709e
commit 212d37fae3
9 changed files with 169 additions and 98 deletions
+10 -4
View File
@@ -383,15 +383,21 @@ TokenInsight 官方亦有提供 RSS,可参考 <https://api.tokeninsight.com/re
<Route author="kdanfly" example="/chinacef/portal/hot" path="/chinacef/portal/hot" radar="1" rssbud="1" />
## 淘股吧股票论坛
## 淘股吧
### 论坛总版
### 淘股论坛
<Route author="emdoe" example="/taoguba/index" path="/taoguba/index"/>
<Route author="emdoe nczitzk" example="/taoguba" path="/taoguba/:category?" :paramsDesc="['分类,见下表,默认为社区总版']">
| 淘股论坛 | 社区总版 | 精华加油 | 网友点赞 |
| ---- | ------- | ------- | ------- |
| bbs | zongban | jinghua | dianzan |
</Route>
### 用户博客
<Route author="emdoe" example="/taoguba/user/252069" path="/taoguba/user/:uid" :paramsDesc="['用户 id']" />
<Route author="emdoe nczitzk" example="/taoguba/blog/252069" path="/taoguba/blog/:id" :paramsDesc="['博客 id,可在对应博客页中找到']" />
## 乌拉邦
+2 -2
View File
@@ -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'));
-46
View File
@@ -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,
};
};
-46
View File
@@ -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,
};
};
+59
View File
@@ -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,
};
};
+67
View File
@@ -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,
};
};
+6
View File
@@ -0,0 +1,6 @@
module.exports = {
'/blog/:id': ['nczitzk'],
'/index': ['nczitzk'],
'/user/:id': ['nczitzk'],
'/:category?': ['nczitzk'],
};
+19
View File
@@ -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',
},
],
},
};
+6
View File
@@ -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'));
};