From d91011da469606b991245617ff9aafdf23ed693a Mon Sep 17 00:00:00 2001
From: Ethan Shen <42264778+nczitzk@users.noreply.github.com>
Date: Wed, 15 Feb 2023 13:00:03 +0800
Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=9D=B1=E7=B6=B2?=
=?UTF-8?q?=E7=94=A2=E7=B6=93=20(#11838)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat(route): add 東網產經
* docs: fix typo
* fix: broken image url
* fix: add industry api url
* fix: no article on certain dates
* docs: move to money18
---
docs/traditional-media.md | 12 ++++
lib/v2/oncc/maintainer.js | 1 +
lib/v2/oncc/money18.js | 115 ++++++++++++++++++++++++++++++
lib/v2/oncc/radar.js | 18 +++--
lib/v2/oncc/router.js | 1 +
lib/v2/oncc/templates/money18.art | 6 ++
6 files changed, 148 insertions(+), 5 deletions(-)
create mode 100644 lib/v2/oncc/money18.js
create mode 100644 lib/v2/oncc/templates/money18.art
diff --git a/docs/traditional-media.md b/docs/traditional-media.md
index 2b3eb74f0..2b8f500d2 100644
--- a/docs/traditional-media.md
+++ b/docs/traditional-media.md
@@ -931,6 +931,8 @@ IT・科学 tech_science
## 东网
+### 即時新聞
+
频道参数可以从官网的地址中获取,如:
@@ -941,6 +943,16 @@ IT・科学 tech_science
+### Money18
+
+
+
+| 新聞總覽 | 全日焦點 | 板塊新聞 | 國際金融 | 大行報告 | A 股新聞 | 地產新聞 | 投資理財 | 新股 IPO | 科技財情 |
+| ---- | ---- | -------- | ---- | -------- | -------- | ---- | --------- | ------ | ---- |
+| exp | fov | industry | int | recagent | ntlgroup | pro | weainvest | ipo | tech |
+
+
+
## 読売新聞
### 新聞
diff --git a/lib/v2/oncc/maintainer.js b/lib/v2/oncc/maintainer.js
index b278b5baa..f8309f4a6 100644
--- a/lib/v2/oncc/maintainer.js
+++ b/lib/v2/oncc/maintainer.js
@@ -1,3 +1,4 @@
module.exports = {
'/:language/:channel?': ['Fatpandac'],
+ '/money18/:id?': ['nczitzk'],
};
diff --git a/lib/v2/oncc/money18.js b/lib/v2/oncc/money18.js
new file mode 100644
index 000000000..bd1137736
--- /dev/null
+++ b/lib/v2/oncc/money18.js
@@ -0,0 +1,115 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const dayjs = require('dayjs');
+const timezone = require('@/utils/timezone');
+const { parseDate } = require('@/utils/parse-date');
+const { art } = require('@/utils/render');
+const path = require('path');
+
+const sections = {
+ exp: '新聞總覽',
+ fov: '全日焦點',
+ industry: '板塊新聞',
+ int: '國際金融',
+ recagent: '大行報告',
+ ntlgroup: 'A股新聞',
+ pro: '地產新聞',
+ weainvest: '投資理財',
+ ipo: '新股IPO',
+ tech: '科技財情',
+};
+
+module.exports = async (ctx) => {
+ const id = ctx.params.id ?? 'exp';
+ const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 30;
+
+ const rootUrl = 'https://money18.on.cc';
+ const currentUrl = `${rootUrl}/finnews/news_${id === 'industry' ? 'industry.html' : `breaking.html?section=${id}`}`;
+ const ipoApiUrl = `https://dyn.on.cc/api/asrh/v1/events/names/新股/articles?page=1&limit=${limit}`;
+ const industryApiUrl = `${rootUrl}/cnt/utf8/content/articleList/sector_list_exp_1.js`;
+
+ const toApiUrl = (date) => `${rootUrl}/cnt/utf8/content/${date}/articleList/list_${id}_all.js`;
+
+ let apiUrl = id === 'ipo' ? ipoApiUrl : id === 'industry' ? industryApiUrl : toApiUrl(dayjs().format('YYYYMMDD')),
+ hasArticle = false,
+ items = [],
+ i = 0,
+ response;
+
+ /* eslint-disable no-await-in-loop */
+
+ while (!hasArticle) {
+ try {
+ response = await got({
+ method: 'get',
+ url: apiUrl,
+ });
+ hasArticle = true;
+ } catch (e) {
+ if (e.code === 'ERR_NON_2XX_3XX_RESPONSE') {
+ hasArticle = false;
+ apiUrl = toApiUrl(dayjs().subtract(++i, 'day').format('YYYYMMDD'));
+ }
+ }
+ }
+
+ /* eslint-enable no-await-in-loop */
+
+ if (id === 'ipo') {
+ items = response.data.articles.map((item) => ({
+ title: item.title,
+ author: item.authorname,
+ link: `${rootUrl}/finnews/content/${id}/${item.articleId}.html`,
+ description: art(path.join(__dirname, 'templates/money18.art'), {
+ images: item.hasHdPhoto ? [`https://hk.on.cc/hk/bkn${item.hdEnlargeThumbnail}`] : undefined,
+ description: item.content,
+ }),
+ pubDate: timezone(parseDate(item.pubDate), +8),
+ }));
+ } else if (id === 'industry') {
+ items = response.data.articles.slice(0, limit).map((item) => ({
+ title: item.title,
+ author: item.authorname,
+ link: `${rootUrl}/finnews/content/${id}/${item.articleId}.html`,
+ category: item.sector.map((s) => s.name),
+ pubDate: timezone(parseDate(item.pubDate), +8),
+ }));
+ } else {
+ items = response.data.slice(0, limit).map((item) => ({
+ title: item.title,
+ author: item.authorname,
+ link: `${rootUrl}/finnews/content/${id}/${item.articleId}.html`,
+ pubDate: timezone(parseDate(item.pubDate), +8),
+ }));
+ }
+
+ if (id !== 'ipo') {
+ 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);
+
+ item.description = art(path.join(__dirname, 'templates/money18.art'), {
+ images: content('.photo img')
+ .toArray()
+ .map((i) => content(i).attr('src')),
+ description: content('.content').html(),
+ });
+
+ return item;
+ })
+ )
+ );
+ }
+
+ ctx.state.data = {
+ title: `東網產經 - ${sections[id]}`,
+ link: currentUrl,
+ item: items,
+ };
+};
diff --git a/lib/v2/oncc/radar.js b/lib/v2/oncc/radar.js
index 397dcd096..9cd88dacc 100644
--- a/lib/v2/oncc/radar.js
+++ b/lib/v2/oncc/radar.js
@@ -4,34 +4,42 @@ module.exports = {
hk: [
{
title: '港澳',
- docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
+ docs: 'https://docs.rsshub.app/traditional-media.html#dong-wang',
source: ['/hk/news/index.html', '/hk/news/index_cn.html'],
target: '/oncc/zh-hans/news',
},
{
title: '两岸',
- docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
+ docs: 'https://docs.rsshub.app/traditional-media.html#dong-wang',
source: ['/hk/cnnews/index.html', '/hk/cnnews/index_cn.html'],
target: '/oncc/zh-hans/cnnews',
},
{
title: '国际',
- docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
+ docs: 'https://docs.rsshub.app/traditional-media.html#dong-wang',
source: ['/hk/intnews/index.html', '/hk/intnews/index_cn.html'],
target: '/oncc/zh-hans/intnews',
},
{
title: '评论',
- docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
+ docs: 'https://docs.rsshub.app/traditional-media.html#dong-wang',
source: ['/hk/commentary/index.html', '/hk/commentary/index_cn.html'],
target: '/oncc/zh-hans/commentary',
},
{
title: '产经',
- docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
+ docs: 'https://docs.rsshub.app/traditional-media.html#dong-wang',
source: ['/hk/finance/index.html', '/hk/finance/index_cn.html'],
target: '/oncc/zh-hans/finance',
},
],
+ money18: [
+ {
+ title: '產經',
+ docs: 'https://docs.rsshub.app/traditional-media.html#dong-wang',
+ source: ['/finnews/news_breaking.html'],
+ target: (params, url) => `/oncc/money18/${new URL(url).searchParams.get('section')}`,
+ },
+ ],
},
};
diff --git a/lib/v2/oncc/router.js b/lib/v2/oncc/router.js
index ab1e01461..1ef1396df 100644
--- a/lib/v2/oncc/router.js
+++ b/lib/v2/oncc/router.js
@@ -1,3 +1,4 @@
module.exports = function (router) {
+ router.get('/money18/:id?', require('./money18'));
router.get('/:language/:channel?', require('./index'));
};
diff --git a/lib/v2/oncc/templates/money18.art b/lib/v2/oncc/templates/money18.art
new file mode 100644
index 000000000..dcb463751
--- /dev/null
+++ b/lib/v2/oncc/templates/money18.art
@@ -0,0 +1,6 @@
+{{ if images }}
+{{ each images image }}
+
+{{ /each }}
+{{ /if }}
+{{@ description }}