From ea921790cae0ca98b4d20657ef7eed5dfbf30f34 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Fri, 2 Jul 2021 15:10:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=91=A9=E7=82=B9?= =?UTF-8?q?=E4=BC=97=E7=AD=B9=20(#7804)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 44 ++++++++++++++++++++++++ lib/router.js | 3 ++ lib/routes/modian/zhongchou.js | 62 ++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 lib/routes/modian/zhongchou.js diff --git a/docs/new-media.md b/docs/new-media.md index 97604b268..d44fce3c5 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1620,6 +1620,50 @@ column 为 third 时可选的 category: +## 梅斯医学 MedSci + +### 推荐 + + + +## 摩点 + +### 众筹 + + + +分类 + +| 全部 | 游戏 | 动漫 | 出版 | 桌游 | +| ---- | ----- | ------ | ---------- | ---------- | +| all | games | comics | publishing | tablegames | + +| 潮玩模型 | 影视 | 音乐 | 活动 | 设计 | +| -------- | ---------- | ----- | ---------- | ------ | +| toys | film-video | music | activities | design | + +| 科技 | 食品 | 爱心通道 | 动物救助 | +| ---------- | ---- | -------- | -------- | +| technology | food | charity | animals | + +| 个人愿望 | 其他 | +| -------- | ------ | +| wishes | others | + +排序 + +| 最新上线 | 金额最高 | 评论最多 | +| -------- | --------- | ----------- | +| top_time | top_money | top_comment | + +状态 + +| 全部 | 创意 | 预热 | 众筹中 | 众筹成功 | +| ---- | ---- | ------- | ------ | -------- | +| all | idea | preheat | going | success | + + + ## 摩根大通研究所 ### 新闻 diff --git a/lib/router.js b/lib/router.js index 8e85538b5..1cfb47b56 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4119,4 +4119,7 @@ router.get('/macau-bolsas/:lang?', require('./routes/macau-bolsas/index')); // 加美财经 router.get('/caus/:category?', require('./routes/caus')); +// 摩点 +router.get('/modian/zhongchou/:category?/:sort?/:status?', require('./routes/modian/zhongchou')); + module.exports = router; diff --git a/lib/routes/modian/zhongchou.js b/lib/routes/modian/zhongchou.js new file mode 100644 index 000000000..40c5b660f --- /dev/null +++ b/lib/routes/modian/zhongchou.js @@ -0,0 +1,62 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const category = ctx.params.category || 'all'; + const sort = ctx.params.sort || 'top_time'; + const status = ctx.params.status || 'all'; + + const rootUrl = 'https://zhongchou.modian.com'; + const currentUrl = `${rootUrl}/${category}/${sort}/${status}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.pro_title') + .slice(0, 12) + .map((_, item) => { + item = $(item).parent(); + + return { + title: item.text(), + link: item.attr('href'), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + const startTime = detailResponse.data.match(/realtime_sync\.pro_time\('(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})', '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}'\);/); + + if (startTime === null) { + item.pubDate = Date.parse(content('.start-time h3').text() || content('h3[start_time]').attr('start_time')); + } else { + item.pubDate = Date.parse(startTime[1]); + } + + item.author = content('span[data-nickname]').text(); + item.description = `
` + content('.center-top').html() + content('#my_back_info').html() + content('#cont_match_htmlstr').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${$('.category div span').text()} - ${$('.status div span').text()} - ${$('.sort div span').text()} - 摩点众筹`, + link: currentUrl, + item: items, + }; +};