rss: mi crowdfunding

This commit is contained in:
DIYgod
2018-07-29 16:11:09 +08:00
parent 8416635f82
commit 0871be17bd
4 changed files with 68 additions and 0 deletions

View File

@@ -187,6 +187,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
- Release note
- 推酷
- 周刊
- 小米
- 众筹
</details>

View File

@@ -1547,3 +1547,13 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到
| 编程狂人 | 设计匠艺 | 创业周刊 | 科技周刊 |
| -------- | -------- | -------- | -------- |
| prog | design | startup | tech |
## 小米
### 众筹
举例: [https://rsshub.app/mi/crowdfunding](https://rsshub.app/mi/crowdfunding)
路由: `/mi/crowdfunding`
参数: 无

View File

@@ -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;

53
routes/mi/crowdfunding.js Normal file
View File

@@ -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}<br>${data.goods.market_price / 100}元<br><img referrerpolicy="no-referrer" src="${item.img}">`,
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,
};
};