From 212d37fae347190e3ec59c940ad13c5bf87ba0e2 Mon Sep 17 00:00:00 2001
From: Ethan Shen <42264778+nczitzk@users.noreply.github.com>
Date: Wed, 10 Aug 2022 22:21:09 +0800
Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=B7=98=E8=82=A1?=
=?UTF-8?q?=E5=90=A7=E6=B7=98=E8=82=A1=E8=AE=BA=E5=9D=9B=20(#10432)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/finance.md | 14 +++++---
lib/router.js | 4 +--
lib/routes/taoguba/index.js | 46 -------------------------
lib/routes/taoguba/user.js | 46 -------------------------
lib/v2/taoguba/blog.js | 59 +++++++++++++++++++++++++++++++
lib/v2/taoguba/index.js | 67 ++++++++++++++++++++++++++++++++++++
lib/v2/taoguba/maintainer.js | 6 ++++
lib/v2/taoguba/radar.js | 19 ++++++++++
lib/v2/taoguba/router.js | 6 ++++
9 files changed, 169 insertions(+), 98 deletions(-)
delete mode 100644 lib/routes/taoguba/index.js
delete mode 100644 lib/routes/taoguba/user.js
create mode 100644 lib/v2/taoguba/blog.js
create mode 100644 lib/v2/taoguba/index.js
create mode 100644 lib/v2/taoguba/maintainer.js
create mode 100644 lib/v2/taoguba/radar.js
create mode 100644 lib/v2/taoguba/router.js
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'));
+};