Skip to content

Commit

Permalink
feat(route): add 摩点众筹 (DIYgod#7804)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Shen authored Jul 2, 2021
1 parent a467c0e commit ea92179
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
44 changes: 44 additions & 0 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,50 @@ column 为 third 时可选的 category:

</Route>

## 梅斯医学 MedSci

### 推荐

<Route author="nczitzk" example="/medsci/recommend" path="/medsci/recommend"/>

## 摩点

### 众筹

<Route author="nczitzk" example="/modian/zhongchou" path="/modian/zhongchou/:category?/:sort?/:status?" :paramsDesc="['分类,见下表,默认为全部', '排序,见下表,默认为最新上线', '状态,见下表,默认为全部']">

分类

| 全部 | 游戏 | 动漫 | 出版 | 桌游 |
| ---- | ----- | ------ | ---------- | ---------- |
| 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 |

</Route>

## 摩根大通研究所

### 新闻
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
62 changes: 62 additions & 0 deletions lib/routes/modian/zhongchou.js
Original file line number Diff line number Diff line change
@@ -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 = `<img src="${content('#big_logo').attr('src')}"><br>` + 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,
};
};

0 comments on commit ea92179

Please sign in to comment.