feat: add deloitte #6248 (#6259)

This commit is contained in:
Laam Pui
2020-11-30 11:22:44 +00:00
committed by GitHub
parent 5badeb2137
commit 2b417516d6
3 changed files with 76 additions and 0 deletions
+10
View File
@@ -58,6 +58,16 @@ pageClass: routes
</Route>
## Deloitte
<Route author="laampui" example="/deloitte/industries/consumer" path="/deloitte/industries/:category?" :paramsDesc="['默认为 energy-resources-industrials']">
| 消费行业 | 能源、资源及工业行业 | 金融服务行业 | 政府及公共服务 | 生命科学与医疗行业 | 科技、传媒及电信行业 |
| -------- | ---------------------------- | ------------------ | -------------------------- | ------------------------ | ----------------------------------- |
| consumer | energy-resources-industrials | financial-services | government-public-services | life-sciences-healthcare | technology-media-telecommunications |
</Route>
## elife
### 最新成果
+3
View File
@@ -3576,6 +3576,9 @@ router.get('/youdao/latest', require('./routes/youdao/latest'));
router.get('/yinxiang/note', require('./routes/yinxiang/note'));
router.get('/yinxiang/card/:id?', require('./routes/yinxiang/card'));
// Deloitte
router.get('/deloitte/industries/:category?', require('./routes/deloitte/industries'));
// 特斯拉系统更新
router.get('/tesla', require('./routes/tesla/update'));
+63
View File
@@ -0,0 +1,63 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const category = ctx.params.category || 'energy-resources-industrials';
const options = {
consumer: {
icid: 'top_consumer',
label: '消费行业',
},
'energy-resources-industrials': {
icid: 'top_energy-resources-industrials',
label: '能源、资源及工业行业',
},
'financial-services': {
icid: 'top_financial-services',
label: '金融服务行业',
},
'government-public-services': {
icid: 'top_government-public-services',
label: '政府及公共服务',
},
'life-sciences-healthcare': {
icid: 'top_life-sciences-healthcare',
label: '生命科学与医疗行业',
},
'technology-media-telecommunications': {
icid: 'top_technology-media-telecommunications',
label: '科技、传媒及电信行业',
},
};
const response = await got({
url: 'https://www2.deloitte.com/cn/zh/industries/energy-resources-industrials.html',
searchParams: {
icid: options[category].icid,
},
});
const $ = cheerio.load(response.data);
const articles = $('.featuredpromo a.promo-focus')
.map((index, ele) => ({
title: $(ele).text().trim(),
link: $(ele).attr('href'),
}))
.get();
const item = await Promise.all(
articles.slice(0, 10).map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got.get(`https://www2.deloitte.com/${item.link}`);
const s = cheerio.load(detailResponse.data);
item.description = s('.two-columns-c0').html();
return Promise.resolve(item);
})
)
);
ctx.state.data = {
title: `Deloitte - ${options[category].label}`,
link: `https://www2.deloitte.com/cn/zh/industries/energy-resources-industrials.html?icid=top_energy-resources-`,
item,
};
};