add 每日安全推送 (#1579)

closes #1577
This commit is contained in:
Chenyang Shi
2019-02-19 22:41:11 +08:00
committed by DIYgod
parent 35240e0e1d
commit 783a005ec6
3 changed files with 50 additions and 0 deletions

View File

@@ -2965,3 +2965,7 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看
### 鲸跃汽车
<route name="首页" author="LogicJake" example="/whalegogo/home" path="/whalegogo/home"/>
### 每日安全
<route name="推送" author="LogicJake" example="/security/pulses" path="/security/pulses"/>

View File

@@ -1065,4 +1065,7 @@ router.get('/hupu/bxj/:id/:order?', require('./routes/hupu/bxj'));
// 牛客网
router.get('/nowcoder/discuss/:type/:order', require('./routes/nowcoder/discuss'));
// 每日安全
router.get('/security/pulses', require('./routes/security/pulses'));
module.exports = router;

View File

@@ -0,0 +1,43 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const url = require('url');
const host = 'https://sec.today';
module.exports = async (ctx) => {
const link = 'https://sec.today/pulses/';
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const out = $('div.endless_page_template div.row')
.slice(0, 10)
.map(function() {
const author = $(this)
.find('div.card-text small.text-muted')
.text()
.trim()
.split('•')[0];
const itemUrl = $(this)
.find('p.card-text.my-3 > a')
.attr('href');
const info = {
link: url.resolve(host, itemUrl),
description: $(this)
.find('p.card-text.my-1')
.html(),
title: $(this)
.find('h5.card-title')
.text(),
author: author,
};
return info;
})
.get();
ctx.state.data = {
title: '每日安全推送',
link: link,
item: out,
};
};