From cfec1ca4465881ca1ec8a312c452feb93fc2c552 Mon Sep 17 00:00:00 2001 From: Chenyang Shi Date: Fri, 26 Apr 2019 18:44:53 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=AF=95=E9=A9=AC=E5=A8=81=E6=B4=9E?= =?UTF-8?q?=E5=AF=9F=20(#1999)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/other.md | 4 +++ lib/router.js | 3 +++ lib/routes/kpmg/insights.js | 54 +++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 lib/routes/kpmg/insights.js diff --git a/docs/other.md b/docs/other.md index e6998d5382..0fa87a38a6 100644 --- a/docs/other.md +++ b/docs/other.md @@ -499,3 +499,7 @@ type 为 all 时,category 参数不支持 cost 和 free ## 马良行 + +## 毕马威 + + diff --git a/lib/router.js b/lib/router.js index 18840132c9..03d7a8b282 100755 --- a/lib/router.js +++ b/lib/router.js @@ -1288,4 +1288,7 @@ router.get('/mlhang', require('./routes/mlhang/latest')); // PlayStation Store router.get('/ps/list/:gridName', require('./routes/ps/list')); +// 毕马威 +router.get('/kpmg/insights', require('./routes/kpmg/insights')); + module.exports = router; diff --git a/lib/routes/kpmg/insights.js b/lib/routes/kpmg/insights.js new file mode 100644 index 0000000000..b41efaa404 --- /dev/null +++ b/lib/routes/kpmg/insights.js @@ -0,0 +1,54 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const url = require('url'); +const host = 'https://home.kpmg'; + +module.exports = async (ctx) => { + const link = 'https://home.kpmg/cn/zh/home/insights.html'; + + const api = 'https://home.kpmg/search/?all_sites=false&site=cn_zh&language=zh&x1=KPMG_Tab_Type&q1=Insights&sort=KPMG_Filter_Date&facets=false'; + const response = await axios({ + method: 'get', + url: api, + headers: { + Referer: link, + }, + }); + const list = response.data['customer-results'].resultset.results.result; + + const out = await Promise.all( + list.map(async (item) => { + const title = item.KPMG_Title; + const itemUrl = url.resolve(host, item.KPMG_URL); + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await axios.get(itemUrl); + const $ = cheerio.load(response.data); + let description = $('div.bodytext-data').html(); + + if ($('a.component-link')) { + const link = $('a.component-link').attr('href'); + description += `

点击下载PDF

`; + } + + const single = { + title: title, + link: itemUrl, + description: description, + }; + ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: '毕马威洞察', + link: link, + description: '欢迎浏览毕马威中国网站的知识库。在这里,你可以找到毕马威中国各类定期出版的通讯及各通讯过往的期号。', + item: out, + }; +};