fix(route): blank results from fx678 (#12722)

* Fix kx.js to fetch the latest news

* make ESLint happy

* Use proper DateTime object

* fix runtime errors

* update `host` to avoid redirection

* refactor: migrate to v2

---------
This commit is contained in:
Jiahao Lee
2023-06-30 20:26:11 +08:00
committed by GitHub
parent 26eeb74250
commit 21e36b3b40
8 changed files with 70 additions and 51 deletions

View File

@@ -368,6 +368,12 @@ TokenInsight 官方亦有提供 RSS可参考 <https://api.tokeninsight.com/re
</Route>
## 汇通网
### 7x24 小时快讯
<Route author="occupy5 dousha" example="/fx678/kx" path="/fx678/kx" radar="1"/>
## 金十数据
### 市场快讯

View File

@@ -2726,12 +2726,6 @@ others = 热点新闻 + 滚动新闻
</Route>
## 汇通网
### 7x24 小时快讯
<Route author="occupy5" example="/fx678/kx" path="/fx678/kx" />
## 机核网
### 分类

View File

@@ -1576,7 +1576,7 @@ router.get('/asahi/area/:id', lazyloadRouteHandler('./routes/asahi/area'));
router.get('/asahi/:genre?/:category?', lazyloadRouteHandler('./routes/asahi/index'));
// 7x24小时快讯
router.get('/fx678/kx', lazyloadRouteHandler('./routes/fx678/kx'));
// router.get('/fx678/kx', lazyloadRouteHandler('./routes/fx678/kx'));
// SoundCloud
router.get('/soundcloud/tracks/:user', lazyloadRouteHandler('./routes/soundcloud/tracks'));

View File

@@ -1,44 +0,0 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
const url = require('url');
const host = 'https://kx.fx678.com/';
module.exports = async (ctx) => {
const link = 'https://kx.fx678.com/';
const res = await got.get(link);
const $ = cheerio.load(res.data);
// 页面新闻消息列表
const list = $('.body_zb ul .body_zb_li .zb_word')
.find('.list_font_pic > a:first-child')
.map((i, e) => $(e).attr('href'))
.slice(0, 30)
.get();
const out = await Promise.all(
list.map(async (itemUrl) => {
const absoluteUrl = url.resolve(host, itemUrl);
const cache = await ctx.cache.get(absoluteUrl);
// 判断缓存
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const res = await got.get(absoluteUrl);
const $ = cheerio.load(res.data);
const item = {
title: $('.article-cont h1').text(),
link: absoluteUrl,
description: $('.article-main .content').html(),
pubDate: new Date().toUTCString(),
};
ctx.cache.set(absoluteUrl, JSON.stringify(item));
return item;
})
);
ctx.state.data = {
title: '7x24小时快讯',
link,
item: out,
};
};

44
lib/v2/fx678/kx.js Normal file
View File

@@ -0,0 +1,44 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const link = 'https://www.fx678.com/kx/';
const res = await got.get(link);
const $ = cheerio.load(res.data);
// 页面新闻消息列表
const list = $('.body_zb ul .body_zb_li .zb_word')
.find('.list_font_pic > a:first-child')
.map((i, e) => $(e).attr('href'))
.slice(0, 30)
.get();
const out = await Promise.all(
list.map((itemUrl) =>
ctx.cache.tryGet(itemUrl, async () => {
const res = await got.get(itemUrl);
const $ = cheerio.load(res.data);
const contentPart = $('.article-main .content').html().trim();
const forewordPart = $('.article-main .foreword').html().trim();
const datetimeString = $('.article-cont .details i').text().trim();
const articlePubDate = timezone(parseDate(datetimeString, 'YYYY-MM-DD HH:mm:ss'), +8);
const item = {
title: $('.article-main .foreword').text().trim().split('——').pop(),
link: itemUrl,
description: contentPart.length > 1 ? contentPart : forewordPart,
pubDate: articlePubDate,
};
return item;
})
)
);
ctx.state.data = {
title: '7x24小时快讯',
link,
item: out,
};
};

View File

@@ -0,0 +1,3 @@
module.exports = {
'/kx': ['occupy5', 'dousha'],
};

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

@@ -0,0 +1,13 @@
module.exports = {
'fx678.com': {
_name: '汇通网',
'.': [
{
title: '7x24 小时快讯',
docs: 'https://docs.rsshub.app/finance.html#hui-tong-wang',
source: ['/kx'],
target: '/fx678/kx',
},
],
},
};

3
lib/v2/fx678/router.js Normal file
View File

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