From 276d86a76e6c88593d86a768caafeeb3a019a644 Mon Sep 17 00:00:00 2001 From: hoilc Date: Tue, 28 Apr 2020 11:17:58 +0800 Subject: [PATCH] feat: add ptpress book (#4577) --- docs/shopping.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/ptpress/book.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 lib/routes/ptpress/book.js diff --git a/docs/shopping.md b/docs/shopping.md index db8990ab2..ed2dca1ee 100644 --- a/docs/shopping.md +++ b/docs/shopping.md @@ -105,6 +105,12 @@ For instance, in https://www.leboncoin.fr/recherche/?**category=10&locations=Par +## 人民邮电出版社 + +### 图书列表 + + + ## 什么值得买 ::: tip 提示 diff --git a/lib/router.js b/lib/router.js index 6a3e35a3a..3cee8501d 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2576,6 +2576,9 @@ router.get('/zhuixinfan/list', require('./routes/zhuixinfan/list')); // scoresaber router.get('/scoresaber/user/:id', require('./routes/scoresaber/user')); +// 人民邮电出版社 +router.get('/ptpress/book/:type?', require('./routes/ptpress/book')); + // 本地宝焦点资讯 router.get('/bendibao/news/:city', require('./routes/bendibao/news')); diff --git a/lib/routes/ptpress/book.js b/lib/routes/ptpress/book.js new file mode 100644 index 000000000..78f3dc06e --- /dev/null +++ b/lib/routes/ptpress/book.js @@ -0,0 +1,34 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const type = ctx.params.type !== 'hot' ? 'publish' : 'hot'; + + const search_page_url = `https://www.ptpress.com.cn/shopping/search?tag=search&orderStr=${type}`; + + const response = await got({ + method: 'post', + url: 'https://www.ptpress.com.cn/bookinfo/getBookListForEBTag', + headers: { + Referer: search_page_url, + }, + form: { + page: 1, + rows: 18, + orderStr: type, + }, + }); + + const list = response.data.data.data; + + ctx.state.data = { + title: `最${type === 'hot' ? '热' : '新'}图书 - 人民邮电出版社`, + link: search_page_url, + item: list.map((item) => ({ + title: `${item.bookName} / ¥${item.discountPrice}`, + author: item.author, + description: ``, + pubDate: new Date(item.stockInDate.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3')), + link: `https://www.ptpress.com.cn/shopping/buy?bookId=${item.bookId}`, + })), + }; +};