Skip to content

Commit

Permalink
Merge pull request #1315 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 Jan 4, 2024
2 parents 989dcab + 9af1349 commit 09a0aaf
Show file tree
Hide file tree
Showing 13 changed files with 481 additions and 44 deletions.
1 change: 1 addition & 0 deletions lib/v2/ft/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
'/myft/:key': ['HenryQW'],
'/:language/:channel?': ['HenryQW', 'xyqfer'],
};
51 changes: 51 additions & 0 deletions lib/v2/ft/myft.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const got = require('@/utils/got');
const parser = require('@/utils/rss-parser');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const ProcessFeed = (content) => {
// clean up the article
content.find('div.o-share, aside, div.o-ads').remove();

return content.html();
};

const link = `https://www.ft.com/myft/following/${ctx.params.key}.rss`;

const feed = await parser.parseURL(link);

const items = await Promise.all(
feed.items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const response = await got({
method: 'get',
url: item.link,
headers: {
Referer: 'https://www.facebook.com',
},
});

const $ = cheerio.load(response.data);

item.description = ProcessFeed($('article.js-article__content-body'));
item.category = [$('.n-content-tag--with-follow').text()].concat(
$('.article__right-bottom a.concept-list__concept')
.map((i, e) => $(e).text().trim())
.get()
);
item.author = $('a.n-content-tag--author')
.map((i, e) => $(e).text())
.get();

return item;
})
)
);

ctx.state.data = {
title: `FT.com - myFT`,
link,
description: `FT.com - myFT`,
item: items,
};
};
13 changes: 13 additions & 0 deletions lib/v2/ft/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ module.exports = {
title: 'FT 中文网',
docs: 'https://docs.rsshub.app/routes/traditional-media#financial-times',
},
{
title: 'myFT 个人 RSS',
docs: 'https://docs.rsshub.app/routes/traditional-media#financial-times',
},
],
},
'ft.com': {
_name: 'Financial Times',
'.': [
{
title: 'myFT personal RSS',
docs: 'https://docs.rsshub.app/routes/en/traditional-media#financial-times',
},
],
},
};
1 change: 1 addition & 0 deletions lib/v2/ft/router.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = function (router) {
router.get('/myft/:key', require('./myft'));
router.get('/:language/:channel?', require('./channel'));
};
110 changes: 110 additions & 0 deletions lib/v2/yicai/dt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');

const columns = {
article: 2,
report: 3,
visualization: 4,
};

module.exports = async (ctx) => {
const { column = 'article', category = '0' } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;

const rootUrl = 'https://dt.yicai.com';
const apiUrl = new URL('api/getNewsList', rootUrl).href;
const currentUrl = new URL(column, rootUrl).href;

const { data: response } = await got(apiUrl, {
searchParams: {
page: 1,
rid: columns[column],
cid: category,
pageSize: limit,
},
});

let items = response.data.data.slice(0, limit).map((item) => {
const enclosureUrl = item.originVideo;
const enclosureExt = enclosureUrl.split(/\./).pop();

return {
title: item.newstitle,
link: new URL(item.url, rootUrl).href,
description: art(path.join(__dirname, 'templates/description.art'), {
image: {
src: item.originPic,
alt: item.newstitle,
},
intro: item.newsnotes,
}),
author: item.creatername,
category: [item.channelrootname, item.channelname, item.NewsTypeName].filter((c) => c),
guid: `yicai-dt-${item.newsid}`,
pubDate: parseDate(item.utc_createdate),
updated: parseDate(item.utc_lastdate),
enclosure_url: enclosureUrl,
enclosure_type: enclosureUrl ? `${enclosureExt === 'mp4' ? 'video' : 'application'}/${enclosureExt}` : undefined,
upvotes: item.newsscore ?? 0,
};
});

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

const content = cheerio.load(detailResponse);

content('div.logintips').remove();

content('img').each((_, e) => {
e = content(e);

content(e).replaceWith(
art(path.join(__dirname, 'templates/description.art'), {
image: {
src: e.prop('data-original') ?? e.prop('src'),
alt: e.prop('alt'),
width: e.prop('width'),
height: e.prop('height'),
},
})
);
});

item.description += art(path.join(__dirname, 'templates/description.art'), {
description: content('div.txt').html(),
});
item.author = content('div.authortime h3').text();

return item;
})
)
);

const { data: currentResponse } = await got(currentUrl);

const $ = cheerio.load(currentResponse);

const title = $('title').text();
const image = $('div.logo a img').prop('src');
const icon = new URL($('link[rel="shortcut icon"]').prop('href'), rootUrl).href;

ctx.state.data = {
item: items,
title: `${$(`a[data-cid="${category}"]`).text()}${title}`,
link: currentUrl,
description: $('meta[name="keywords"]').prop('content'),
language: 'zh',
image,
icon,
logo: icon,
subtitle: $('meta[name="description"]').prop('content'),
author: title.split(/_/).pop(),
allowEmpty: true,
};
};
1 change: 1 addition & 0 deletions lib/v2/yicai/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
'/author/:id?': ['nczitzk'],
'/brief': ['sanmmm', 'nczitzk'],
'/dt/:column?/:category?': ['nczitzk'],
'/feed/:id?': ['nczitzk'],
'/headline': ['nczitzk'],
'/latest': ['nczitzk'],
Expand Down
164 changes: 164 additions & 0 deletions lib/v2/yicai/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,169 @@ module.exports = {
target: '/yicai/author/:id',
},
],
dt: [
{
title: 'DT 财经 - 可视化 - 全部',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/visualization'],
target: '/yicai/dt/visualization/0',
},
{
title: 'DT 财经 - 可视化 - 新流行',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/visualization'],
target: '/yicai/dt/visualization/39',
},
{
title: 'DT 财经 - 可视化 - 新趋势',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/visualization'],
target: '/yicai/dt/visualization/40',
},
{
title: 'DT 财经 - 可视化 - 商业黑马',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/visualization'],
target: '/yicai/dt/visualization/41',
},
{
title: 'DT 财经 - 可视化 - 新品',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/visualization'],
target: '/yicai/dt/visualization/42',
},
{
title: 'DT 财经 - 可视化 - 营销',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/visualization'],
target: '/yicai/dt/visualization/43',
},
{
title: 'DT 财经 - 可视化 - 大公司',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/visualization'],
target: '/yicai/dt/visualization/44',
},
{
title: 'DT 财经 - 可视化 - 城市生活',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/visualization'],
target: '/yicai/dt/visualization/45',
},
{
title: 'DT 财经 - 文章 - 全部',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/article'],
target: '/yicai/dt/article/0',
},
{
title: 'DT 财经 - 文章 - 新流行',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/article'],
target: '/yicai/dt/article/31',
},
{
title: 'DT 财经 - 文章 - 新趋势',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/article'],
target: '/yicai/dt/article/32',
},
{
title: 'DT 财经 - 文章 - 商业黑马',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/article'],
target: '/yicai/dt/article/33',
},
{
title: 'DT 财经 - 文章 - 新品',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/article'],
target: '/yicai/dt/article/34',
},
{
title: 'DT 财经 - 文章 - 营销',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/article'],
target: '/yicai/dt/article/35',
},
{
title: 'DT 财经 - 文章 - 大公司',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/article'],
target: '/yicai/dt/article/36',
},
{
title: 'DT 财经 - 文章 - 城市生活',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/article'],
target: '/yicai/dt/article/38',
},
{
title: 'DT 财经 - 报告 - 全部',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/report'],
target: '/yicai/dt/report/0',
},
{
title: 'DT 财经 - 报告 - 人群观念',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/report'],
target: '/yicai/dt/report/9',
},
{
title: 'DT 财经 - 报告 - 人群行为',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/report'],
target: '/yicai/dt/report/22',
},
{
title: 'DT 财经 - 报告 - 美妆个护',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/report'],
target: '/yicai/dt/report/23',
},
{
title: 'DT 财经 - 报告 - 3C数码',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/report'],
target: '/yicai/dt/report/24',
},
{
title: 'DT 财经 - 报告 - 营销趋势',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/report'],
target: '/yicai/dt/report/25',
},
{
title: 'DT 财经 - 报告 - 服饰鞋包',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/report'],
target: '/yicai/dt/report/27',
},
{
title: 'DT 财经 - 报告 - 互联网',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/report'],
target: '/yicai/dt/report/28',
},
{
title: 'DT 财经 - 报告 - 城市与居住',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/report'],
target: '/yicai/dt/report/29',
},
{
title: 'DT 财经 - 报告 - 消费趋势',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/report'],
target: '/yicai/dt/report/30',
},
{
title: 'DT 财经 - 报告 - 生活趋势',
docs: 'https://docs.rsshub.app/routes/traditional-media#di-yi-cai-jing-dt-cai-jing',
source: ['/report'],
target: '/yicai/dt/report/37',
},
],
},
};
1 change: 1 addition & 0 deletions lib/v2/yicai/router.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = function (router) {
router.get('/author/:id?', require('./author'));
router.get('/brief', require('./brief'));
router.get('/dt/:column?/:category?', require('./dt'));
router.get('/feed/:id?', require('./feed'));
router.get('/headline', require('./headline'));
router.get('/latest', require('./latest'));
Expand Down
Loading

0 comments on commit 09a0aaf

Please sign in to comment.