From 783a005ec6db6fe5cf0071a7539211ea97fc4af1 Mon Sep 17 00:00:00 2001 From: Chenyang Shi Date: Tue, 19 Feb 2019 22:41:11 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=AF=8F=E6=97=A5=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E6=8E=A8=E9=80=81=20(#1579)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #1577 --- docs/README.md | 4 ++++ lib/router.js | 3 +++ lib/routes/security/pulses.js | 43 +++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 lib/routes/security/pulses.js diff --git a/docs/README.md b/docs/README.md index cba9209e1..70c775500 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2965,3 +2965,7 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看 ### 鲸跃汽车 + +### 每日安全 + + diff --git a/lib/router.js b/lib/router.js index 3fb48fc98..51930b2f9 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/security/pulses.js b/lib/routes/security/pulses.js new file mode 100644 index 000000000..17b6665e1 --- /dev/null +++ b/lib/routes/security/pulses.js @@ -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, + }; +};