feat: add 城农 Growin' City 城农资讯观点 (#6715)

This commit is contained in:
Ethan Shen 2021-01-18 04:51:49 +08:00 committed by GitHub
parent 594b4c8fe6
commit df8beee2f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 77 additions and 0 deletions

View File

@ -774,6 +774,30 @@ Supported sub-sites:
</Route>
## 城农 Growin' City
### 城农资讯观点
<Route author="nczitzk" example="/growincity/news" path="/growincity/news/:id?" anticrawler="1" :paramsDesc="['分类 id见下表默认为原创内容']">
| 原创内容 | 商业投资 | 观点评论 | 农业科技 |
| -------- | -------- | -------- | -------- |
| 48 | 55 | 88 | 98 |
| 农艺管理 | 农业机械 | 设施农业 | 畜牧水产 |
| -------- | -------- | -------- | -------- |
| 101 | 83 | 85 | 87 |
| 食品科技 | 科技产品 | 食品创新 | 研究报告 |
| -------- | -------- | -------- | -------- |
| 86 | 100 | 99 | 76 |
| 教育拓展 | 展会培训 | 业界访谈 |
| -------- | -------- | -------- |
| 61 | 77 | 72 |
</Route>
## 抽屉新热榜
### 最新

View File

@ -3888,4 +3888,7 @@ router.get('/chiculture/topic/:category?', require('./routes/chiculture/topic'))
router.get('/cqut/news', require('./routes/universities/cqut/cqut-news'));
router.get('/cqut/libnews', require('./routes/universities/cqut/cqut-libnews'));
// 城农 Growin' City
router.get('/growincity/news/:id?', require('./routes/growincity/news'));
module.exports = router;

View File

@ -0,0 +1,50 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const id = ctx.params.id || '48';
const rootUrl = 'http://www.growincity.com';
const currentUrl = `${rootUrl}?page_id=11112&qfyuuid=qfy_posts_grid_s6lpz&q_term=${id}&q_type=post`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.link_title')
.slice(0, 10)
.map((_, item) => {
item = $(item);
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);
item.description = content('div[qfyuuid="qfy_column_text_view_rgnpn"]').html();
item.pubDate = new Date(detailResponse.data.match(/>发布时间:<\/span>(\d{4}-\d{2}-\d{2} \d{2}:\d{2})/)[1]).toUTCString();
return item;
})
)
);
ctx.state.data = {
title: "城农资讯观点 - 城农 Growin' City",
link: currentUrl,
item: items,
};
};