diff --git a/README.md b/README.md index 6a504f2ab..05837dba8 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - Release note - 推酷 - 周刊 +- 小米 + - 众筹 diff --git a/docs/README.md b/docs/README.md index 3fe6c6759..284a22e49 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1547,3 +1547,13 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到 | 编程狂人 | 设计匠艺 | 创业周刊 | 科技周刊 | | -------- | -------- | -------- | -------- | | prog | design | startup | tech | + +## 小米 + +### 众筹 + +举例: [https://rsshub.app/mi/crowdfunding](https://rsshub.app/mi/crowdfunding) + +路由: `/mi/crowdfunding` + +参数: 无 diff --git a/router.js b/router.js index c17bb0b65..bd1a05f4e 100755 --- a/router.js +++ b/router.js @@ -354,4 +354,7 @@ router.get('/firefox/release/:platform', require('./routes/firefox/release')); // tuicool router.get('/tuicool/mags/:type', require('./routes/tuicool/mags')); +// 小米 +router.get('/mi/crowdfunding', require('./routes/mi/crowdfunding')); + module.exports = router; diff --git a/routes/mi/crowdfunding.js b/routes/mi/crowdfunding.js new file mode 100644 index 000000000..d9de48da2 --- /dev/null +++ b/routes/mi/crowdfunding.js @@ -0,0 +1,53 @@ +const axios = require('../../utils/axios'); +const config = require('../../config'); + +module.exports = async (ctx) => { + const baseUrl = 'https://home.mi.com/app/shop/content?id=s8939d03918810635'; + const response = await axios({ + method: 'get', + url: baseUrl, + headers: { + 'User-Agent': config.ua, + }, + }); + + const data = response.data.match(/,gid:(\d*),src:"(.+?)"/g).map((item) => ({ + gid: item.match(/gid:(\d*)/)[1], + img: item.match(/src:"(.+?)"/)[1], + })); + + const out = await Promise.all( + data.map(async (item) => { + const key = `microwdfunding${item.gid}`; + const value = await ctx.cache.get(key); + let result; + if (value) { + result = JSON.parse(value); + } else { + const response = await axios({ + method: 'get', + url: `https://home.mi.com/app/shop/jsonp?k=test&m=Product&a=GetDetail&p={%22gid%22:${item.gid}}&_=${+new Date()}&callback=Zepto1532846359142`, + headers: { + 'User-Agent': config.ua, + Referer: baseUrl, + }, + }); + const data = JSON.parse(response.data.match(/^Zepto1532846359142\((.*)\);$/)[1]).data || {}; + result = { + title: data.goods.name, + description: `${data.goods.summary}
${data.goods.market_price / 100}元
`, + pubDate: new Date(data.crowdfunding.start * 1000).toUTCString(), + link: `https://youpin.mi.com/detail?gid=${item.gid}`, + }; + ctx.cache.set(key, JSON.stringify(result), 12 * 60 * 60); + } + return Promise.resolve(result); + }) + ); + + ctx.state.data = { + title: '小米众筹', + link: baseUrl, + item: out, + }; +};