Skip to content

Commit

Permalink
Merge pull request #124 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 e94ab95 + 9af1349 commit d543787
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 48 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'));
};
53 changes: 28 additions & 25 deletions lib/v2/yicai/dt.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,53 @@ const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');

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

module.exports = async (ctx) => {
const { type = 'article', category = '0' } = ctx.params;
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(type, rootUrl).href;
const currentUrl = new URL(column, rootUrl).href;

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

let items = response.data.data.slice(0, limit).map((item) => ({
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: item.originVideo,
enclosure_type: item.originVideo ? `video/${item.originVideo.split(/\./).pop()}` : undefined,
upvotes: item.newsscore ?? 0,
}));
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) =>
Expand Down Expand Up @@ -75,8 +80,6 @@ module.exports = async (ctx) => {
description: content('div.txt').html(),
});
item.author = content('div.authortime h3').text();
item.enclosure_url = '';
item.enclosure_type = 'video/mp4';

return item;
})
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@
"@stylistic/eslint-plugin-js": "1.5.3",
"@types/aes-js": "3.1.4",
"@types/crypto-js": "4.2.1",
"@types/eslint": "8.56.0",
"@types/eslint": "8.56.1",
"@types/eslint-config-prettier": "6.11.3",
"@types/etag": "1.8.3",
"@types/fs-extra": "11.0.4",
"@types/git-rev-sync": "2.0.2",
"@types/html-to-text": "9.0.4",
"@types/imapflow": "1.0.16",
"@types/imapflow": "1.0.17",
"@types/jsdom": "21.1.6",
"@types/json-bigint": "1.0.4",
"@types/koa": "2.13.12",
Expand All @@ -181,7 +181,7 @@
"@types/supertest": "6.0.2",
"@types/tiny-async-pool": "2.0.3",
"@types/tough-cookie": "4.0.5",
"@vercel/nft": "0.26.0",
"@vercel/nft": "0.26.2",
"cross-env": "7.0.3",
"eslint": "8.56.0",
"eslint-config-prettier": "9.1.0",
Expand Down
40 changes: 20 additions & 20 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions website/docs/routes/traditional-media.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@
- 频道包含多重路径,如 `http://www.ftchinese.com/rss/column/007000002` 则替换 `/``-` `/ft/chinese/column-007000002`.
</Route>

### myFT personal RSS {#financial-times-myft-personal-rss}

<Route author="HenryQW" example="/ft/myft/rss-key" path="/ft/myft/:key" paramsDesc={['the last part of myFT personal RSS address']} configRequired="1">
:::tip
- Visit ft.com -> myFT -> Contact Preferences to enable personal RSS feed, see [help.ft.com](https://help.ft.com/faq/email-alerts-and-contact-preferences/what-is-myft-rss-feed/)
- Obtain the key from the personal RSS address, it looks like `12345678-abcd-4036-82db-vdv20db024b8`
:::
</Route>

## Korean Central News Agency (KCNA) 朝鲜中央通讯社 {#korean-central-news-agency-kcna-chao-xian-zhong-yang-tong-xun-she}

### News {#korean-central-news-agency-kcna-chao-xian-zhong-yang-tong-xun-she-news}
Expand Down

0 comments on commit d543787

Please sign in to comment.