From 2ae32eac80309fe48dfbb7dfc5db093f4b59d71c Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 9 Sep 2019 16:28:33 +0800 Subject: [PATCH] feat: add pintu360 --- docs/other.md | 14 +++++++++ lib/router.js | 3 ++ lib/routes/pintu360/index.js | 55 ++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 lib/routes/pintu360/index.js diff --git a/docs/other.md b/docs/other.md index 52f94dd981..cc21867a9a 100644 --- a/docs/other.md +++ b/docs/other.md @@ -1324,3 +1324,17 @@ type 为 all 时,category 参数不支持 cost 和 free ### 全文 + +## 品途商业评论 + +### 文章 + + + +类型 + +| 推荐 | 零售前沿 | 智能科技 | 泛文娱 | 教育 | 大健康 | 新消费 | 创业投资 | +| ---- | -------- | -------- | ------ | ---- | ------ | ------ | -------- | +| 0 | 7 | 10 | 9 | 98 | 70 | 8 | 72 | + + diff --git a/lib/router.js b/lib/router.js index 4e92d3c36a..229e3d8b17 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1704,4 +1704,7 @@ router.get('/nfmovies/:id?', require('./routes/nfmovies/index')); // 书友社区 router.get('/andyt/:view?', require('./routes/andyt/index')); +// 品途商业评论 +router.get('/pintu360/:type?', require('./routes/pintu360/index')); + module.exports = router; diff --git a/lib/routes/pintu360/index.js b/lib/routes/pintu360/index.js new file mode 100644 index 0000000000..68229f2168 --- /dev/null +++ b/lib/routes/pintu360/index.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const type = ctx.params.type || '0'; + + const response = await got({ + method: 'post', + url: 'https://www.pintu360.com/service/ajax_article_service.php', + headers: { + Referer: 'https://www.pintu360.com/', + }, + form: true, + data: { + fnName: 'getArticleList', + type: type === '0' ? 'recommend' : 'classId', + id: type, + pageNumber: 0, + duration: 'quarter', + }, + }); + const data = response.data; + + const items = await Promise.all( + data.slice(0, 10).map(async (item) => { + const link = `https://www.pintu360.com/a${item.id}.html?${item.op}`; + return Promise.resolve({ + title: item.title, + description: await ctx.cache.tryGet(link, async () => { + const res = await got(link); + const $ = cheerio.load(res.data); + return $('.article-content .text').html(); + }), + pubDate: new Date(item.createTime).toUTCString(), + link, + }); + }) + ); + + const titleMap = { + '0': '推荐', + '7': '零售前沿', + '10': '智能科技', + '9': '泛文娱', + '98': '教育', + '70': '大健康', + '8': '新消费', + '72': '创业投资', + }; + ctx.state.data = { + title: `品途商业评论-${titleMap[type]}`, + link: type === '0' ? 'https://www.pintu360.com/' : `https://www.pintu360.com/articleList-${type}.html`, + item: items, + }; +};