add 新浪科技探索 (#1483)

This commit is contained in:
Chenyang Shi
2019-01-29 15:41:42 +08:00
committed by DIYgod
parent 9f9dcd4913
commit 795120f453
3 changed files with 66 additions and 0 deletions

View File

@@ -2833,3 +2833,14 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看
### 移动支付网
<route name="新闻" author="LogicJake" example="/mpaypass/news" path="/mpaypass/news"/>
### 新浪科技
<route name="科学探索" author="LogicJake" example="/sina/discovery/zx" path="/sina/discovery/:type" :paramsDesc="['订阅分区类型']>
分类:
| zx | twhk | dwzw | zrdl | lskg | smyx | shbk | kjqy |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| 最新 | 天文航空 | 动物植物 | 自然地理 | 历史考古 | 生命医学 | 生活百科 | 科技前沿 |
</route>

View File

@@ -1013,4 +1013,7 @@ router.get('/fitchratings/site/:type', require('./routes/fitchratings/site'));
// 移动支付
router.get('/mpaypass/news', require('./routes/mpaypass/news'));
// 新浪科技探索
router.get('/sina/discovery/:type', require('./routes/sina/discovery'));
module.exports = router;

View File

@@ -0,0 +1,52 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const link = 'https://tech.sina.com.cn/discovery/';
const api = 'https://feed.sina.com.cn/api/roll/get?pageid=207&num=10&versionNumber=1.2.4&page=1&encode=utf-8&lid=';
const map = new Map([
['zx', { title: '最新', id: '1795' }],
['twhk', { title: '天文航空', id: '1796' }],
['dwzw', { title: '动物植物', id: '1797' }],
['zrdl', { title: '自然地理', id: '1798' }],
['lskg', { title: '历史考古', id: '1799' }],
['smyx', { title: '生命医学', id: '1800' }],
['shbk', { title: '生活百科', id: '1801' }],
['kjqy', { title: '科技前沿', id: '1802' }],
]);
module.exports = async (ctx) => {
const type = ctx.params.type;
const id = map.get(type).id;
const title = map.get(type).title;
const api_url = api + id;
const response = await axios.get(api_url);
const list = response.data.result.data;
const out = await Promise.all(
list.map(async (data) => {
const title = data.title;
const date = data.intime * 1000;
const itemUrl = data.url;
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const description = $('.article').html();
const single = {
title: title,
link: itemUrl,
description: description,
pubDate: new Date(date).toUTCString(),
};
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `${title}-新浪科技科学探索`,
link: link,
item: out,
};
};