Skip to content

Commit

Permalink
Merge pull request #930 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored May 3, 2023
2 parents 6e29b6f + 479c982 commit aa2a201
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 133 deletions.
2 changes: 1 addition & 1 deletion docs/anime.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ pageClass: routes

::: warning 注意

用户动态需要 iwara 登录后的 Cookie 值,所以只能自建,详情见[部署页面](/install/#route-specific-configurations)的配置模块。
用户动态需要 iwara 用户名和密码,所以只能自建,详情见[部署页面](/install/#route-specific-configurations)的配置模块。

:::

Expand Down
2 changes: 1 addition & 1 deletion docs/en/anime.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ If you subscribe to [Discounted works Latest Discounts - Newest to Oldest](https

::: warning

This route requires Cookie, therefore it's only available when self-hosting, refer to the [Deploy Guide](/en/install/#route-specific-configurations) for route-specific configurations.
This route requires username and password, therefore it's only available when self-hosting, refer to the [Deploy Guide](/en/install/#route-specific-configurations) for route-specific configurations.

:::

Expand Down
3 changes: 2 additions & 1 deletion docs/en/install/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,8 @@ See docs of the specified route and `lib/config.js` for detailed information.
- Iwara:
- `IWARA_COOKIE`: Cookie of Iwara User
- `IWARA_USERNAME`: username of Iwara User
- `IWARA_PASSWORD`: password of Iwara User
- Last.fm
Expand Down
8 changes: 4 additions & 4 deletions docs/finance.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,15 @@ TokenInsight 官方亦有提供 RSS,可参考 <https://api.tokeninsight.com/re

<Route author="nczitzk" example="/cls/depth/1000" path="/cls/depth/:category?" :paramsDesc="['分类代码,可在首页导航栏的目标网址 URL 中找到']" radar="1">

| 头条 | 股市 | 港股 | 环球 | 公司 | 券商 | 基金 | 地产 | 金融 | 汽车 | 科创版 | 品见 | 期货 | 投教 |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ------ | ---- | ---- | ---- |
| 1000 | 1003 | 1135 | 1007 | 1005 | 1118 | 1110 | 1006 | 1032 | 1119 | 1111 | 1160 | 1124 | 1176 |
| 头条 | 股市 | 港股 | 环球 | 公司 | 券商 | 基金 | 地产 | 金融 | 汽车 | 科创 | 创业版 | 品见 | 期货 | 投教 |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ------ | ---- | ---- | ---- |
| 1000 | 1003 | 1135 | 1007 | 1005 | 1118 | 1110 | 1006 | 1032 | 1119 | 1111 | 1127 | 1160 | 1124 | 1176 |

</Route>

### 热门文章排行榜

<Route author="5upernova-heng" example="/cls/hot" path="/cls/hot" radar="1"/>
<Route author="5upernova-heng nczitzk" example="/cls/hot" path="/cls/hot" radar="1"/>

## 第一财经杂志

Expand Down
3 changes: 2 additions & 1 deletion docs/install/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,8 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行

- Iwara:

- `IWARA_COOKIE`: Iwara 登录后的 Cookie 值
- `IWARA_USERNAME`: Iwara 用户名
- `IWARA_PASSWORD`: Iwara 密码

- Last.fm 全部路由:[申请地址](https://www.last.fm/api/)

Expand Down
3 changes: 2 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ const calculateValue = () => {
cookie: envs.IG_COOKIE,
},
iwara: {
cookie: envs.IWARA_COOKIE,
username: envs.IWARA_USERNAME,
password: envs.IWARA_PASSWORD,
},
lastfm: {
api_key: envs.LASTFM_API_KEY,
Expand Down
66 changes: 34 additions & 32 deletions lib/v2/cls/depth.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { app, os, sv, getSignedSearchParams } = require('./utils');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');

const config = {
const { rootUrl, getSearchParams } = require('./utils');

const categories = {
1000: '头条',
1003: '股市',
1135: '港股',
Expand All @@ -15,59 +17,59 @@ const config = {
1006: '地产',
1032: '金融',
1119: '汽车',
1111: '科创版',
1111: '科创',
1127: '创业版',
1160: '品见',
1124: '期货',
1176: '投教',
};

module.exports = async (ctx) => {
const category = ctx.params.category || '1000';
const title = config[category];
const category = ctx.params.category ?? '1000';
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 50;

const title = categories[category];

if (!title) {
throw Error('Bad category. See <a href="https://docs.rsshub.app/finance.html#cai-lian-she-shen-du">docs</a>');
}
const searchParams = getSignedSearchParams({
app,
os,
sv,
});
const baseUrl = 'https://www.cls.cn';
const link = `${baseUrl}/v3/depth/home/assembled/${category}`;

const apiUrl = `${rootUrl}/v3/depth/home/assembled/${category}`;
const currentUrl = `${rootUrl}/depth?id=${category}`;

const response = await got({
method: 'get',
url: link,
searchParams,
url: apiUrl,
searchParams: getSearchParams(),
});

let list =
response.data.data.depth_list?.map((item) => ({
let items = response.data.data.top_article
.concat(response.data.data.depth_list)
.slice(0, limit)
.map((item) => ({
title: item.title || item.brief,
link: `${baseUrl}/detail/${item.id}`,
pubDate: new Date(item.ctime * 1000).toUTCString(),
})) || [];
link: `${rootUrl}/detail/${item.id}`,
pubDate: parseDate(item.ctime * 1000),
author: item.source,
}));

list = list.concat(
response.data.data.top_article.map((item) => ({
title: item.title || item.brief,
link: `${baseUrl}/detail/${item.id}`,
pubDate: new Date(item.ctime * 1000).toUTCString(),
}))
);

const items = await Promise.all(
list.map((item) =>
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);

const nextData = JSON.parse(content('script#__NEXT_DATA__').text());
const articleDetail = nextData.props.initialState.detail.articleDetail;

item.description = art(path.join(__dirname, 'templates/depth.art'), { articleDetail });
item.author = articleDetail.author?.name;
item.author = articleDetail.author?.name ?? item.author ?? '';
item.description = art(path.join(__dirname, 'templates/depth.art'), {
articleDetail,
});

return item;
})
Expand All @@ -76,7 +78,7 @@ module.exports = async (ctx) => {

ctx.state.data = {
title: `财联社 - ${title}`,
link: `${baseUrl}/depth?id=${category}`,
link: currentUrl,
item: items,
};
};
67 changes: 38 additions & 29 deletions lib/v2/cls/hot.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,54 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { app, os, sv, getSignedSearchParams } = require('./utils');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');

async function getDescription(link, ctx) {
const description = await ctx.cache.tryGet(link, async () => {
const detailResponse = await got({
method: 'get',
url: link,
});
const content = cheerio.load(detailResponse.data);

return content('div.detail-content').html();
});
return description;
}
const { rootUrl, getSearchParams } = require('./utils');

module.exports = async (ctx) => {
const searchParams = getSignedSearchParams({
app,
os,
sv,
});
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 50;

const apiUrl = `${rootUrl}/v2/article/hot/list`;

const link = 'https://www.cls.cn/v2/article/hot/list';
const response = await got({
method: 'get',
url: link,
searchParams,
url: apiUrl,
searchParams: getSearchParams(),
});
const items = await Promise.all(
response.data.data.map(async (item) => ({
title: item.title || item.brief,
link: `https://www.cls.cn/detail/${item.id}`,
pubDate: new Date(item.ctime * 1000).toUTCString(),
description: await getDescription(`https://www.cls.cn/detail/${item.id}`, ctx),
}))

let items = response.data.data.slice(0, limit).map((item) => ({
title: item.title || item.brief,
link: `${rootUrl}/detail/${item.id}`,
pubDate: parseDate(item.ctime * 1000),
}));

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);

const nextData = JSON.parse(content('script#__NEXT_DATA__').text());
const articleDetail = nextData.props.initialState.detail.articleDetail;

item.author = articleDetail.author?.name ?? item.author ?? '';
item.description = art(path.join(__dirname, 'templates/depth.art'), {
articleDetail,
});

return item;
})
)
);

ctx.state.data = {
title: '财联社 - 热门文章排行榜',
link: 'https://www.cls.cn/',
link: rootUrl,
item: items,
};
};
2 changes: 1 addition & 1 deletion lib/v2/cls/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
'/depth/:category?': ['nczitzk'],
'/hot': ['5upernova-heng'],
'/hot': ['5upernova-heng', 'nczitzk'],
'/telegraph/:category?': ['nczitzk'],
};
2 changes: 1 addition & 1 deletion lib/v2/cls/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
{
title: '深度',
docs: 'https://docs.rsshub.app/finance.html#cai-lian-she',
source: ['/depth'],
source: ['/depth', '/'],
target: (_, url) => `/cls/depth/${new URL(url).searchParams.get('id')}`,
},
{
Expand Down
48 changes: 25 additions & 23 deletions lib/v2/cls/telegraph.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const got = require('@/utils/got');
const { app, os, sv, getSignedSearchParams } = require('./utils');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');

const titles = {
const { rootUrl, getSearchParams } = require('./utils');

const categories = {
watch: '看盘',
announcement: '公司',
explain: '解读',
Expand All @@ -15,38 +17,38 @@ const titles = {
};

module.exports = async (ctx) => {
const category = ctx.params.category || '';
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 30;

const searchParams = getSignedSearchParams({
app,
category,
hasFirstVipArticle: 1,
os,
rn: limit,
sv,
});
let link = 'https://www.cls.cn/nodeapi/updateTelegraphList';
const category = ctx.params.category ?? '';
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 50;

let apiUrl = `${rootUrl}/nodeapi/updateTelegraphList`;
if (category) {
link = 'https://www.cls.cn/v1/roll/get_roll_list';
apiUrl = `${rootUrl}/v1/roll/get_roll_list`;
}

const currentUrl = `${rootUrl}/telegraph`;

const response = await got({
method: 'get',
url: link,
searchParams,
url: apiUrl,
searchParams: getSearchParams({
category,
hasFirstVipArticle: 1,
}),
});

const list = response.data.data.roll_data.map((item) => ({
const items = response.data.data.roll_data.slice(0, limit).map((item) => ({
title: item.title || item.content,
link: item.shareurl,
description: art(path.join(__dirname, 'templates/telegraph.art'), { item }),
pubDate: new Date(item.ctime * 1000).toUTCString(),
description: art(path.join(__dirname, 'templates/telegraph.art'), {
item,
}),
pubDate: parseDate(item.ctime * 1000),
category: item.subjects?.map((s) => s.subject_name),
}));

ctx.state.data = {
title: `财联社 - 电报${category === '' ? '' : ` - ${titles[category]}`}`,
link: 'https://www.cls.cn/telegraph',
item: list,
title: `财联社 - 电报${category === '' ? '' : ` - ${categories[category]}`}`,
link: currentUrl,
item: items,
};
};
6 changes: 3 additions & 3 deletions lib/v2/cls/templates/depth.art
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ if articleDetail.images }}
{{ each articleDetail.images i }}
<img src="{{ i }}">
{{ /each }}
{{ each articleDetail.images i }}
<img src="{{ i }}">
{{ /each }}
<br>
{{ /if }}

Expand Down
10 changes: 5 additions & 5 deletions lib/v2/cls/templates/telegraph.art
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{{ if item.content }}
{{ item.content }}
{{ item.content }}
{{ /if }}

{{ if item.images }}
{{ if item.images.length !== 0 }}
<br>
{{ each item.images i }}
<img src="{{ i }}">
{{ /each }}
{{ each item.images i }}
<img src="{{ i }}">
{{ /each }}
{{ /if }}
Loading

1 comment on commit aa2a201

@vercel
Copy link

@vercel vercel bot commented on aa2a201 May 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.