feat: 路透社 实时资讯 (#5080)

This commit is contained in:
black-desk 2020-07-02 12:23:11 +08:00 committed by GitHub
parent b622409a62
commit e20830b9a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 0 deletions

View File

@ -282,6 +282,14 @@ category 对应的关键词有
</Route>
## 路透社
### 实时资讯
<Route author="black-desk" example="/reuters/theWire" path="/reuters/theWire">
</Route>
## 每经网
### 重磅原创

View File

@ -2902,6 +2902,9 @@ router.get('/erbingapp/news', require('./routes/erbingapp/news'));
// 电商报
router.get('/dsb/area/:area', require('./routes/dsb/area'));
// Reuters
router.get('/reuters/theWire', require('./routes/reuters/theWire'));
// 格隆汇
router.get('/gelonghui/user/:id', require('./routes/gelonghui/user'));
router.get('/gelonghui/subject/:id', require('./routes/gelonghui/subject'));

View File

@ -0,0 +1,45 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const date = require('@/utils/date');
module.exports = async (ctx) => {
const url = `https://cn.reuters.com/assets/jsonWireNews`;
const response = await got({
method: 'get',
url: url,
});
const data = response.data;
const list_item = data.headlines.map((item) => {
const info = {
title: item.headline,
link: 'https://cn.reuters.com' + item.url,
pubDate: date(item.formattedDate),
};
return info;
});
function getDescription(items) {
return Promise.all(
items.map(async function (currentValue) {
currentValue.description = await ctx.cache.tryGet(currentValue.link, async () => {
const r = await got({
url: currentValue.link,
method: 'get',
});
const $ = cheerio.load(r.data);
return $('.StandardArticle_content').html();
});
return currentValue;
})
);
}
await getDescription(list_item).then(function () {
ctx.state.data = {
title: '路透社 - 实时资讯',
link: `https://cn.reuters.com/theWire`,
item: list_item,
};
});
};