From 2b417516d630932593fba5166b6d646332204972 Mon Sep 17 00:00:00 2001 From: Laam Pui Date: Mon, 30 Nov 2020 19:22:44 +0800 Subject: [PATCH] feat: add deloitte #6248 (#6259) --- docs/journal.md | 10 +++++ lib/router.js | 3 ++ lib/routes/deloitte/industries.js | 63 +++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 lib/routes/deloitte/industries.js diff --git a/docs/journal.md b/docs/journal.md index e6afbbc349..78b7111bcf 100644 --- a/docs/journal.md +++ b/docs/journal.md @@ -58,6 +58,16 @@ pageClass: routes +## Deloitte + + + +| 消费行业 | 能源、资源及工业行业 | 金融服务行业 | 政府及公共服务 | 生命科学与医疗行业 | 科技、传媒及电信行业 | +| -------- | ---------------------------- | ------------------ | -------------------------- | ------------------------ | ----------------------------------- | +| consumer | energy-resources-industrials | financial-services | government-public-services | life-sciences-healthcare | technology-media-telecommunications | + + + ## elife ### 最新成果 diff --git a/lib/router.js b/lib/router.js index 17cecdde10..b13123ca91 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/deloitte/industries.js b/lib/routes/deloitte/industries.js new file mode 100644 index 0000000000..51e001bea6 --- /dev/null +++ b/lib/routes/deloitte/industries.js @@ -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, + }; +};