增加经济观察网 (#1099)

增加经济观察网
This commit is contained in:
epirus
2018-11-10 15:57:14 +08:00
committed by DIYgod
parent f2f2d25d43
commit 0a8f937460
4 changed files with 79 additions and 6 deletions

View File

@@ -2261,3 +2261,13 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
| hot | pop |
</route>
### 经济观察网
category 对应的关键词有
| 时事 | 政策 | 证券 | 资本 | 理财 | 新科技 | 大健康 | 房产 | 汽车 | 消费 | 影视 | 娱乐 | 体育 | 教育 | 观察家 | 专栏 | 书评 | 个人历史 |
| ---- | ---- | ---- | ---- | ---- | ------ | ------ | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ------ | ---- | ---- | -------- |
<route name="经济观察网" author="epirus" example="/eeo/观察家" path="/eeo/:category" :paramsDesc="['分类']"/>

View File

@@ -37,12 +37,19 @@ We welcome all pull requests. Suggestions and feedback are also welcomed [here](
- Use component slot for complicated description:
```vue
<routeEn name="Flight Deals" author="HenryQW" path="/hopper/:lowestOnly/:from/:to?" example="/hopper/1/LHR/PEK" :paramsDesc="['set to `1` will return the cheapest deal only, instead of all deals, so you don\'t get spammed', 'origin airport IATA code', 'destination airport IATA code, if unset the destination will be set to `anywhere`']" >
This route returns a list of flight deals (in most cases, 6 flight deals) for a period defined by Hopper's algorithm, which means the travel date will be totally random (could be tomorrow or 10 months from now).
For airport IATA code please refer to [Wikipedia List of airports by IATA code](https://en.wikipedia.org/wiki/List_of_airports_by_IATA_code:_A)
<routeEn
name="Flight Deals"
author="HenryQW"
path="/hopper/:lowestOnly/:from/:to?"
example="/hopper/1/LHR/PEK"
:paramsDesc="[
'set to `1` will return the cheapest deal only, instead of all deals, so you don\'t get spammed',
'origin airport IATA code',
'destination airport IATA code, if unset the destination will be set to `anywhere`',
]"
>
This route returns a list of flight deals (in most cases, 6 flight deals) for a period defined by Hopper's algorithm, which means the travel date will be totally random (could be tomorrow or 10 months from now). For
airport IATA code please refer to [Wikipedia List of airports by IATA code](https://en.wikipedia.org/wiki/List_of_airports_by_IATA_code:_A)
</routeEn>
```

View File

@@ -781,4 +781,7 @@ router.get('/xiachufang/user/cooked/:id', require('./routes/xiachufang/user/cook
router.get('/xiachufang/user/created/:id', require('./routes/xiachufang/user/created'));
router.get('/xiachufang/popular/:timeframe?', require('./routes/xiachufang/popular'));
// 经济观察报
router.get('/eeo/:category?', require('./routes/eeo/index'));
module.exports = router;

53
routes/eeo/index.js Normal file
View File

@@ -0,0 +1,53 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const category = ctx.params.category || '观察家';
const category_url_relation = {
时事: 'http://www.eeo.com.cn/yaowen/dashi/',
政策: 'http://www.eeo.com.cn/yaowen/hfggzc/',
宏观: 'http://www.eeo.com.cn/yaowen/hfshuju/',
证券: 'http://www.eeo.com.cn/jinrong/zhengquan/',
资本: 'http://www.eeo.com.cn/jinrong/ziben/',
理财: 'http://www.eeo.com.cn/jinrong/licai/',
新科技: 'http://www.eeo.com.cn/shangye/xinnengyuan/',
大健康: 'http://www.eeo.com.cn/shangye/yiliao/',
房产: 'http://www.eeo.com.cn/fcqcxf/dichan/',
汽车: 'http://www.eeo.com.cn/fcqcxf/qiche/',
消费: 'http://www.eeo.com.cn/fcqcxf/xiaofei/',
影视: 'http://www.eeo.com.cn/yule/yingshi/',
娱乐: 'http://www.eeo.com.cn/yule/yule/',
体育: 'http://www.eeo.com.cn/yule/tiyu/',
教育: 'http://www.eeo.com.cn/yule/jiaoyu/',
观察家: 'http://www.eeo.com.cn/gcj/guanchajia/',
专栏: 'http://www.eeo.com.cn/gcj/zhuanlan/',
书评: 'http://www.eeo.com.cn/gcj/shuping/',
个人历史: 'http://www.eeo.com.cn/gcj/lishi/',
};
const response = await axios({
method: 'get',
url: category_url_relation[category],
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('#lyp_article li').get();
const result = list.map((item) => ({
title: $(item)
.find('div span a')
.text(),
description: $(item)
.find('div p')
.text(),
pubDate: new Date().toUTCString(),
link: $(item)
.find('>a')
.attr('href'),
}));
ctx.state.data = {
title: '经济观察网',
link: 'http://www.eeo.com.cn',
description: '经济观察网是《经济观察报》社倾力制作的全新商业资讯平台',
item: result,
};
};