Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): caixin global #13519

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions lib/v2/caixinglobal/latest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const { data } = await got('https://gateway.caixin.com/api/extapi/homeInterface.jsp', {
searchParams: {
subject: '100990318;100990314;100990311',
start: 0,
count: ctx.query.limit ? parseInt(ctx.query.limit, 10) : 20,
type: '2',
_: Date.now(),
},
});

const list = data.datas.map((e) => ({
title: e.desc,
description: e.summ,
link: e.link,
pubDate: parseDate(e.time),
category: e.tags.map((t) => t.name),
nid: e.nid,
attr: e.attr,
enclosure_url: e.audioUrl,
enclosure_type: e.audioUrl ? 'audio/mpeg' : undefined,
itunes_item_image: e.audioUrl ? e.pict.imgs[0].url : undefined,
}));

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data } = await got(item.link);
const $ = cheerio.load(data);
$('.loadingBox, .cons-pay-tip').remove();

let content = $('#appContent').prop('outerHTML');

if (item.attr === 0) {
const { data } = await got('https://u.caixinglobal.com/get/reading.do', {
searchParams: {
id: item.nid,
source: '',
url: item.link,
_: Date.now(),
},
});
content = data.data.content;
}

item.description = $('.cons-photo').prop('outerHTML') + content;

return item;
})
)
);

ctx.state.data = {
title: 'The Latest Top Headlines on China - Caixin Global',
description: 'The latest headlines on China finance, companies, politics, international affairs and other China-related issues from around the world. Caixin Global',
language: 'en',
link: 'https://www.caixinglobal.com/news/',
item: items,
};
};
3 changes: 3 additions & 0 deletions lib/v2/caixinglobal/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/latest': ['TonyRL'],
};
13 changes: 13 additions & 0 deletions lib/v2/caixinglobal/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'caixinglobal.com': {
_name: 'Caixin Global',
'.': [
{
title: 'Latest News',
docs: 'https://docs.rsshub.app/routes/traditional-media#caixin-global',
source: ['/news', '/'],
target: '/caixinglobal/latest',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/caixinglobal/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/latest', require('./latest'));
};
6 changes: 6 additions & 0 deletions website/docs/routes/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ Refer to [Boston.com's feed page](https://www.boston.com/rss-feeds) for tags. Fo

</Route>

## Caixin Global {#caixin-global}

### Latest News {#caixin-global-latest-news}

<Route author="TonyRL" example="/caixinglobal/latest" path="/caixinglobal/latest" radar="1" />

## Canadian Broadcasting Corporation {#canadian-broadcasting-corporation}

### News {#canadian-broadcasting-corporation-news}
Expand Down
Loading