Skip to content

Commit

Permalink
Merge pull request #654 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] committed Sep 28, 2022
2 parents f6494be + b0216ca commit 5c591d1
Show file tree
Hide file tree
Showing 17 changed files with 230 additions and 11 deletions.
10 changes: 10 additions & 0 deletions docs/en/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,16 @@ Provides a better reading experience (full text articles) over the official one.

</RouteEn>

## Kuwait Local

### Latest News

<RouteEn author="TonyRL" example="/kuwaitlocal" path="/kuwaitlocal" radar="1" rssbud="1"/>

### Categorised News

<RouteEn author="TonyRL" example="/kuwaitlocal/article" path="/kuwaitlocal/:category?" :paramsDesc="['Category name, can be found in URL, `latest` by default']" radar="1" rssbud="1"/>

## Letterboxd

### User diary
Expand Down
12 changes: 12 additions & 0 deletions docs/en/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ Generates full-text feeds that the official feed doesn't provide.

</RouteEn>

## CNBC

### Full article RSS

<RouteEn author="TonyRL" example="/cnbc/rss" path="/cnbc/rss/:id?" :paramsDesc="['Channel ID, can be found in Official RSS URL, `100003114` (Top News) by default']">

Provides a better reading experience (full articles) over the official ones.

Support all channels, refer to [CNBC RSS feeds](https://www.cnbc.com/rss-feeds/).

</RouteEn>

## Deutsche Welle

### News
Expand Down
2 changes: 1 addition & 1 deletion docs/programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ GitHub 官方也提供了一些 RSS:

### 分类订阅

<Route author="qwertyuiop6" example="/anquanke/week" path="/anquanke/:category" :paramsDesc="['分类订阅']" radar="1" rssbud="1">
<Route author="qwertyuiop6" example="/anquanke/week" path="/anquanke/:category/:fulltext?" :paramsDesc="['分类订阅', '是否获取全文,如需获取全文参数传入 `quanwen` 或 `fulltext`']" radar="1" rssbud="1">

| 360 网络安全周报 | 活动 | 知识 | 资讯 | 招聘 | 工具 |
| ---------- | -------- | --------- | ---- | --- | ---- |
Expand Down
12 changes: 12 additions & 0 deletions docs/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ pageClass: routes

</Route>

## CNBC

### 全文 RSS

<Route author="TonyRL" example="/cnbc/rss" path="/cnbc/rss/:id?" :paramsDesc="['频道 ID,可在官方频道 RSS URL 中找到,留空为 `100003114` (Top News)']">

通过提取文章全文,以提供比官方源更佳的阅读体验。

支持所有频道,频道名称见 [官方频道 RSS](https://www.cnbc.com/rss-feeds/)

</Route>

## Deutsche Welle 德国之声

### 新闻
Expand Down
28 changes: 21 additions & 7 deletions lib/v2/anquanke/category.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
const api = 'https://api.anquanke.com/data/v1/posts?size=10&page=1&category=';
const type = ctx.params.category;
const fulltext = ctx.params.fulltext;
const host = 'https://www.anquanke.com';
const res = await got(`${api}${type}`);
const dataArray = res.data.data;

const items = dataArray.map((item) => ({
title: item.title,
description: item.desc,
pubDate: timezone(parseDate(item.date), +8),
link: `${host}/${type === 'week' ? 'week' : 'post'}/id/${item.id}`,
author: item.author.nickname,
}));
const items = await Promise.all(
dataArray.map(async (item) => {
const art_url = `${host}/${type === 'week' ? 'week' : 'post'}/id/${item.id}`;
return {
title: item.title,
description:
fulltext === 'fulltext' || fulltext === 'quanwen'
? await ctx.cache.tryGet(art_url, async () => {
const { data: res } = await got(art_url);
const content = cheerio.load(res);
return content('#js-article').html();
})
: item.desc,
pubDate: timezone(parseDate(item.date), +8),
link: art_url,
author: item.author.nickname,
};
})
);

ctx.state.data = {
title: `安全客-${dataArray[0].category_name}`,
Expand Down
2 changes: 1 addition & 1 deletion lib/v2/anquanke/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
// '/vul': ['qwertyuiop6'],
'/:category': ['qwertyuiop6'],
'/:category/:fulltext?': ['qwertyuiop6'],
};
2 changes: 1 addition & 1 deletion lib/v2/anquanke/router.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = (router) => {
// router.get('/vul', require('./vul')); // 404
router.get('/:category', require('./category'));
router.get('/:category/:fulltext?', require('./category'));
};
3 changes: 3 additions & 0 deletions lib/v2/cnbc/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/rss/:id?': ['TonyRL'],
};
21 changes: 21 additions & 0 deletions lib/v2/cnbc/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
'cnbc.com': {
_name: 'CNBC',
search: [
{
title: '全文 RSS',
docs: 'https://docs.rsshub.app/traditional-media.html#cnbc',
source: ['/rs/search/combinedcms/view.xml'],
target: (_, url) => `/cnbc/rss/${new URL(url).searchParams.get('id')}`,
},
],
www: [
{
title: '全文 RSS',
docs: 'https://docs.rsshub.app/traditional-media.html#cnbc',
source: ['/id/:id/device/rss/rss.html'],
target: '/cnbc/rss/:id',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/cnbc/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/rss/:id?', require('./rss'));
};
54 changes: 54 additions & 0 deletions lib/v2/cnbc/rss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const parser = require('@/utils/rss-parser');

module.exports = async (ctx) => {
const { id = '100003114' } = ctx.params;
const feed = await parser.parseURL(`https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=${id}`);

const items = await Promise.all(
feed.items
.filter((i) => !i.link.startsWith('https://www.cnbc.com/select/'))
.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);

delete item.content;
delete item.contentSnippet;
delete item.isoDate;

item.description = '';
if ($('.RenderKeyPoints-keyPoints').length) {
$('.RenderKeyPoints-keyPoints').html();
}
if ($('.FeaturedContent-articleBody').length) {
item.description += $('.FeaturedContent-articleBody').html();
}
if ($('.ArticleBody-articleBody').length) {
item.description += $('.ArticleBody-articleBody').html();
}
if ($('.LiveBlogBody-articleBody').length) {
item.description += $('.LiveBlogBody-articleBody').html();
}
if ($('.ClipPlayer-clipPlayer').length) {
item.description += $('.ClipPlayer-clipPlayer').html();
}

const meta = JSON.parse($('[type=application/ld+json]').last().text());
item.author = meta.author ? (meta.author.name ? meta.author.name : meta.author.map((a) => a.name).join(', ')) : null;
item.category = meta.keywords;

return item;
})
)
);

ctx.state.data = {
title: feed.title,
link: feed.link,
description: feed.description,
item: items,
language: feed.language,
};
};
47 changes: 47 additions & 0 deletions lib/v2/kuwaitlocal/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');

const baseUrl = 'https://kuwaitlocal.com';

module.exports = async (ctx) => {
const { category = 'latest' } = ctx.params;
const url = `${baseUrl}/news/${category === 'latest' ? category : `categories/${category}`}`;

const { data: response } = await got(url);
const $ = cheerio.load(response);
const list = $('.news_list a')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: baseUrl + item.attr('href'),
};
});

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);

item.pubDate = parseDate($('.date_icon').next().text());
$('[id^=div-gpt-ad], .pad_10_0, .hide_desktop').remove();
item.description = $('.mob_pad_view').html();
item.category = $('.news_tags a')
.toArray()
.map((item) => $(item).text());
return item;
})
)
);

ctx.state.data = {
title: $('head title').text().trim(),
description: $('head meta[name="description"]').attr('content').trim(),
link: url,
item: items,
language: 'en',
};
};
4 changes: 4 additions & 0 deletions lib/v2/kuwaitlocal/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'/': ['TonyRL'],
'/:category?': ['TonyRL'],
};
19 changes: 19 additions & 0 deletions lib/v2/kuwaitlocal/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
'kuwaitlocal.com': {
_name: 'Kuwait Local',
'.': [
{
title: 'Latest News',
docs: 'https://docs.rsshub.app/en/new-media.html#kuwait-local',
source: ['/news/latest', '/news', '/'],
target: '/kuwaitlocal',
},
{
title: 'Categorised News',
docs: 'https://docs.rsshub.app/en/new-media.html#kuwait-local',
source: ['/news/categories/:category'],
target: '/kuwaitlocal/:category',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/kuwaitlocal/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:category?', require('./index'));
};
8 changes: 7 additions & 1 deletion lib/v2/wallstreetcn/live.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');

const titles = {
global: '要闻',
Expand Down Expand Up @@ -30,9 +32,13 @@ module.exports = async (ctx) => {
.map((item) => ({
link: item.uri,
title: item.title || item.content_text,
description: item.content + (item.content_more ?? ''),
pubDate: parseDate(item.display_time * 1000),
author: item.author?.display_name ?? '',
description: art(path.join(__dirname, 'templates/description.art'), {
description: item.content,
more: item.content_more,
images: item.images,
}),
}));

ctx.state.data = {
Expand Down
11 changes: 11 additions & 0 deletions lib/v2/wallstreetcn/templates/description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{ if description }}
{{@ description }}
{{ /if }}
{{ if more }}
{{@ more }}
{{ /if }}
{{ if images }}
{{ each images image }}
<img src="{{ image.uri }}" width="{{ image.width }}" height="{{ image.height }}">
{{ /each }}
{{ /if }}

1 comment on commit 5c591d1

@vercel
Copy link

@vercel vercel bot commented on 5c591d1 Sep 28, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

rsshub – ./

rsshub-narcissu.vercel.app
rsshub-git-master-narcissu.vercel.app
rsshub.tari.xyz

Please sign in to comment.