+
### 时事新闻
diff --git a/lib/v2/finviz/news.js b/lib/v2/finviz/news.js
index 961676f2d02299..7ba6389929c206 100644
--- a/lib/v2/finviz/news.js
+++ b/lib/v2/finviz/news.js
@@ -3,43 +3,67 @@ const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
+const categories = {
+ news: 0,
+ blogs: 1,
+};
+
module.exports = async (ctx) => {
- const category = ctx.params.category ?? 'news';
+ const { category = 'News' } = ctx.params;
+ const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 200;
+
+ if (!categories.hasOwnProperty(category.toLowerCase())) {
+ throw Error(`No category '${category}'.`);
+ }
const rootUrl = 'https://finviz.com';
- const currentUrl = `${rootUrl}/news.ashx`;
+ const currentUrl = new URL('news.ashx', rootUrl).href;
- const response = await got({
- method: 'get',
- url: currentUrl,
- });
+ const { data: response } = await got(currentUrl);
- const $ = cheerio.load(response.data);
+ const $ = cheerio.load(response);
- const items = $('.table-fixed')
- .eq(category === 'blog' ? 1 : 0)
- .find('.nn')
+ const items = $('table.table-fixed')
+ .eq(categories[category.toLowerCase()])
+ .find('tr.nn')
+ .slice(0, limit)
.toArray()
.map((item) => {
item = $(item);
- const a = item.find('.nn-tab-link');
+ const a = item.find('a.nn-tab-link');
+
+ const descriptionMatches = a
+ .parent()
+ .prop('data-boxover')
+ ?.match(/(.*?)<\/td>/);
+ const authorMatches = item
+ .find('use')
+ .first()
+ .prop('href')
+ ?.match(/#(.*?)-(light|dark)/);
return {
title: a.text(),
- link: a.attr('href'),
- pubDate: timezone(parseDate(item.find('.nn-date').text(), ['MMM-DD', 'HH:mmA']), -4),
- description:
- item
- .find('td[data-boxover]')
- .attr('data-boxover')
- ?.match(/ | ([\s\S]*)<\/td>/)[1] ?? '',
+ link: a.prop('href'),
+ description: descriptionMatches ? descriptionMatches[1] : undefined,
+ author: authorMatches ? authorMatches[1].replace(/-/g, ' ') : 'finviz',
+ pubDate: timezone(parseDate(item.find('td.nn-date').text(), ['HH:mmA', 'MMM-DD']), -4),
};
- });
+ })
+ .filter((item) => item.title);
+
+ const icon = $('link[rel="icon"]').prop('href');
ctx.state.data = {
+ item: items,
title: `finviz - ${category}`,
link: currentUrl,
- item: items,
+ description: $('meta[name="description"]').prop('content'),
+ language: 'en-US',
+ image: new URL($('a.logo svg use').first().prop('href'), rootUrl).href,
+ icon,
+ logo: icon,
+ subtitle: $('title').text(),
};
};
diff --git a/lib/v2/odaily/maintainer.js b/lib/v2/odaily/maintainer.js
index 2e79926bf9d698..a74b1a94aa1a0b 100644
--- a/lib/v2/odaily/maintainer.js
+++ b/lib/v2/odaily/maintainer.js
@@ -1,6 +1,7 @@
module.exports = {
'/activity': ['nczitzk'],
'/newsflash': ['nczitzk'],
+ '/search/news/:keyword': ['snowraincloud'],
'/user/:id': ['nczitzk'],
'/:id?': ['nczitzk'],
};
diff --git a/lib/v2/odaily/radar.js b/lib/v2/odaily/radar.js
index aaec22636a8b68..f18063dc84ded5 100644
--- a/lib/v2/odaily/radar.js
+++ b/lib/v2/odaily/radar.js
@@ -1,60 +1,40 @@
+const odaily = {
+ _name: 'Odaily 星球日报',
+ '.': [
+ {
+ title: '快讯',
+ docs: 'https://docs.rsshub.app/new-media.html#odaily-xing-qiu-ri-bao-kuai-xun',
+ source: ['/newsflash', '/'],
+ target: '/odaily/newsflash',
+ },
+ {
+ title: '搜索快讯',
+ docs: 'https://docs.rsshub.app/new-media.html#odaily-xing-qiu-ri-bao-sou-suo-kuai-xun',
+ source: ['/search/:keyword'],
+ target: '/odaily/search/news/:keyword',
+ },
+ {
+ title: '文章',
+ docs: 'https://docs.rsshub.app/new-media.html#odaily-xing-qiu-ri-bao-wen-zhang',
+ source: ['/'],
+ target: '/odaily/:id?',
+ },
+ {
+ title: '用户文章',
+ docs: 'https://docs.rsshub.app/new-media.html#odaily-xing-qiu-ri-bao-yong-hu-wen-zhang',
+ source: ['/user/:id', '/'],
+ target: '/odaily/user/:id',
+ },
+ {
+ title: '活动',
+ docs: 'https://docs.rsshub.app/new-media.html#odaily-xing-qiu-ri-bao-huo-dong',
+ source: ['/activityPage', '/'],
+ target: '/odaily/activity',
+ },
+ ],
+};
+
module.exports = {
- 'odaily.news': {
- _name: 'Odaily 星球日报',
- '.': [
- {
- title: '快讯',
- docs: 'https://docs.rsshub.app/new-media.html#odaily-xing-qiu-ri-bao-kuai-xun',
- source: ['/newsflash', '/'],
- target: '/odaily/newsflash',
- },
- {
- title: '文章',
- docs: 'https://docs.rsshub.app/new-media.html#odaily-xing-qiu-ri-bao-wen-zhang',
- source: ['/'],
- target: '/odaily/:id?',
- },
- {
- title: '用户文章',
- docs: 'https://docs.rsshub.app/new-media.html#odaily-xing-qiu-ri-bao-yong-hu-wen-zhang',
- source: ['/user/:id', '/'],
- target: '/odaily/user/:id',
- },
- {
- title: '活动',
- docs: 'https://docs.rsshub.app/new-media.html#odaily-xing-qiu-ri-bao-huo-dong',
- source: ['/activityPage', '/'],
- target: '/odaily/activity',
- },
- ],
- },
- '0daily.com': {
- _name: 'Odaily 星球日报',
- '.': [
- {
- title: '快讯',
- docs: 'https://docs.rsshub.app/new-media.html#odaily-xing-qiu-ri-bao-kuai-xun',
- source: ['/newsflash', '/'],
- target: '/odaily/newsflash',
- },
- {
- title: '文章',
- docs: 'https://docs.rsshub.app/new-media.html#odaily-xing-qiu-ri-bao-wen-zhang',
- source: ['/'],
- target: '/odaily/:id?',
- },
- {
- title: '用户文章',
- docs: 'https://docs.rsshub.app/new-media.html#odaily-xing-qiu-ri-bao-yong-hu-wen-zhang',
- source: ['/user/:id', '/'],
- target: '/odaily/user/:id',
- },
- {
- title: '活动',
- docs: 'https://docs.rsshub.app/new-media.html#odaily-xing-qiu-ri-bao-huo-dong',
- source: ['/activityPage', '/'],
- target: '/odaily/activity',
- },
- ],
- },
+ 'odaily.news': odaily,
+ '0daily.com': odaily,
};
diff --git a/lib/v2/odaily/router.js b/lib/v2/odaily/router.js
index 84da30c1c15718..e5de2000d0bae5 100644
--- a/lib/v2/odaily/router.js
+++ b/lib/v2/odaily/router.js
@@ -1,6 +1,7 @@
module.exports = function (router) {
router.get('/activity', require('./activity'));
router.get('/newsflash', require('./newsflash'));
+ router.get('/search/news/:keyword', require('./search_news'));
router.get('/user/:id', require('./user'));
router.get('/:id?', require('./post'));
};
diff --git a/lib/v2/odaily/search_news.js b/lib/v2/odaily/search_news.js
new file mode 100644
index 00000000000000..65dcae6466cd15
--- /dev/null
+++ b/lib/v2/odaily/search_news.js
@@ -0,0 +1,26 @@
+const got = require('@/utils/got');
+const timezone = require('@/utils/timezone');
+const { parseDate } = require('@/utils/parse-date');
+const { rootUrl } = require('./utils');
+
+module.exports = async (ctx) => {
+ const currentUrl = `${rootUrl}/api/pp/api/search/entity-search?per_page=${ctx.query.limit ?? 25}&keyword=${ctx.params.keyword}&entity_type=newsflash`;
+
+ const response = await got({
+ method: 'get',
+ url: currentUrl,
+ });
+
+ const items = response.data.data.items.map((item) => ({
+ title: item.title,
+ link: item.news_url,
+ pubDate: timezone(parseDate(item.published_at), +8),
+ description: ` ${item.description} `,
+ }));
+
+ ctx.state.data = {
+ title: '快讯 - Odaily星球日报',
+ link: `${rootUrl}/search/${ctx.params.keyword}`,
+ item: items,
+ };
+};
diff --git a/lib/v2/telegram/radar.js b/lib/v2/telegram/radar.js
index 1449ddf099a0e5..6a110ba8f9e1b5 100644
--- a/lib/v2/telegram/radar.js
+++ b/lib/v2/telegram/radar.js
@@ -7,8 +7,7 @@ module.exports = {
docs: 'https://docs.rsshub.app/social-media.html#telegram',
source: '/:username',
target: (params, url, document) => {
- const isChannel = document && document.querySelector('.tgme_action_button_label');
- if (isChannel) {
+ if (document?.querySelector('a[href^="/s/"]')) {
return '/telegram/channel/:username';
}
},
|