fix(route): 天天基金 (#7651)

* fix(route):天天基金

* refactor: migrate to v2

Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
This commit is contained in:
ZZL 2022-02-22 05:02:20 +08:00 committed by GitHub
parent 5a59ec4521
commit 925bc6352c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 89 additions and 38 deletions

View File

@ -102,6 +102,12 @@ pageClass: routes
</Route>
## 东方财富
### 天天基金用户动态
<Route author="zidekuls" example="/eastmoney/ttjj/user/6551094298949188" path="/eastmoney/ttjj/user/:uid" :paramsDesc="['用户id, 可以通过天天基金App分享用户主页到浏览器在相应的URL中找到']"/>
## 富途牛牛
### 要闻
@ -203,12 +209,6 @@ pageClass: routes
<Route author="emdoe" example="/taoguba/user/252069" path="/taoguba/user/:uid" :paramsDesc="['用户 id']" />
## 天天基金
### 用户动态
<Route author="zidekuls" example="/eastmoney/user/6551094298949188" path="/eastmoney/user/:uid" :paramsDesc="['用户 id, 可在用户主页 URL 中找到']"/>
## 乌拉邦
### 最新研报

View File

@ -2682,8 +2682,8 @@ router.get('/ccnuwu', lazyloadRouteHandler('./routes/universities/ccnu/ccnuwu'))
// WEEX
router.get('/weexcn/news/:typeid', lazyloadRouteHandler('./routes/weexcn/index'));
// 天天基金
router.get('/eastmoney/user/:uid', lazyloadRouteHandler('./routes/eastmoney/user'));
// 天天基金 migrated to v2
// router.get('/eastmoney/ttjj/user/:uid', lazyloadRouteHandler('./routes/eastmoney/ttjj/user'));
// 紳士漫畫
router.get('/ssmh', lazyloadRouteHandler('./routes/ssmh'));

View File

@ -1,30 +0,0 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const uid = ctx.params.uid;
const response = await got({
method: 'get',
headers: {
Accept: '*/*',
Host: 'i.eastmoney.com',
'Accept-Encoding': 'gzip, deflate, br',
'Cache-Control': 'no-cache',
},
url: `https://i.eastmoney.com/api/ta/UserPostList?p=1&ps=20&uid=${uid}`,
});
const data = response.data.data.re;
const username = data[0].post_user.user_nickname;
ctx.state.data = {
title: `天天基金-${username}的主页`,
link: `https://i.eastmoney.com//${uid}`,
description: `${username} 的 动态`,
item: data.map((item) => ({
title: item.post_title,
description: item.post_content,
pubDate: item.post_display_time,
link: `http://guba.eastmoney.com/news,${item.code_name},${item.post_id}.html`,
})),
};
};

13
lib/v2/eastmoney/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'eastmoney.com': {
_name: '东方财富',
fundbarmob: [
{
title: '天天基金用户动态',
docs: 'https://docs.rsshub.app/finance.html#dong-fang-cai-fu',
source: ['/'],
target: (_param, url) => `/eastmoney/ttjj/user/${new URL(url).searchParams.get('userid')}`,
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/ttjj/user/:uid', require('./ttjj/user'));
};

View File

@ -0,0 +1,65 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const uid = ctx.params.uid;
const urlPrefix = 'https://jijinbaapi.eastmoney.com/gubaapi/v3/read';
const userProfileUrl = `${urlPrefix}/User/UserInfo.ashx?ServerVersion=1.0.0&PhoneType=windows&Location=zh-CN&ctoken=&utoken=&deviceid=000000&ps=8&plat=Wap&product=Fund&version=201&followuid=`;
const userProfileResponse = await got(`${userProfileUrl}${uid}`);
const username = userProfileResponse.data.user_nickname || '不存在的用户';
const userPostListUrl = `${urlPrefix}/Article/Post/UserPostList.ashx`;
const listResponse = await got({
method: 'post',
url: userPostListUrl,
headers: {
Accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
},
form: {
uid,
deviceId: 666666,
version: 201,
p: 1,
ps: 20,
},
});
const data = listResponse.data.re;
const userArticleUrl = `${urlPrefix}/Article/Post/ArticleContent.ashx`;
const result = await Promise.all(
data.map((item) =>
ctx.cache.tryGet(userArticleUrl + item.post_id, async () => {
const detailResponse = await got({
method: 'post',
url: userArticleUrl,
headers: {
Accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `postid=${item.post_id}&ServerVersion=1.0.0&PhoneType=windows&Location=zh-CN&ctoken=&utoken=&deviceId=000000&userId=&plat=Wap&product=Fund&version=201`,
});
const description = detailResponse.data.post.post_content;
const single = {
title: item.post_title,
description,
pubDate: timezone(parseDate(item.post_display_time, 'YYYY-MM-DD HH:mm:ss'), +8),
link: `https://fundbarmob.eastmoney.com/index.html?goPage=articleView&lastPage=personDetailView&aid=${item.post_id}`,
};
return single;
})
)
);
ctx.state.data = {
title: `天天基金-${username}的主页`,
link: `https://fundbarmob.eastmoney.com/index.html?goPage=personDetailView&userid=${uid}`,
description: `${username} 的动态`,
item: result,
};
};