From 20650ca4965795cc333d2af384824c2890d8af08 Mon Sep 17 00:00:00 2001 From: Chenyang Shi Date: Mon, 10 Dec 2018 14:19:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=EF=BC=9A=E5=8D=97=E4=BA=AC?= =?UTF-8?q?=E8=88=AA=E7=A9=BA=E8=88=AA=E5=A4=A9=E5=A4=A7=E5=AD=A6=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E6=9C=BA=E5=AD=A6=E9=99=A2=E5=AD=A6=E6=9C=AF=E8=AE=B2?= =?UTF-8?q?=E5=BA=A7=20(#1254)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 + router.js | 1 + routes/universities/nuaa/cs/academic.js | 64 +++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 routes/universities/nuaa/cs/academic.js diff --git a/docs/README.md b/docs/README.md index 19fc8b7f7..bc337aa07 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1268,6 +1268,8 @@ GitHub 官方也提供了一些 RSS: + + ### 哈尔滨工业大学 diff --git a/router.js b/router.js index 824e4d9fc..7619dd321 100644 --- a/router.js +++ b/router.js @@ -540,6 +540,7 @@ router.get('/seu/yzb/:type', require('./routes/universities/seu/yzb')); // 南京航空航天大学 router.get('/nuaa/jwc/:type?', require('./routes/universities/nuaa/jwc/jwc')); +router.get('/nuaa/cs/academic', require('./routes/universities/nuaa/cs/academic')); // 哈尔滨工业大学 router.get('/hit/jwc', require('./routes/universities/hit/jwc')); diff --git a/routes/universities/nuaa/cs/academic.js b/routes/universities/nuaa/cs/academic.js new file mode 100644 index 000000000..a058f0d51 --- /dev/null +++ b/routes/universities/nuaa/cs/academic.js @@ -0,0 +1,64 @@ +const axios = require('../../../../utils/axios'); +const cheerio = require('cheerio'); +const url = require('url'); + +const host = 'http://cs.nuaa.edu.cn/'; + +module.exports = async (ctx) => { + const link = url.resolve(host, '1975/list.htm'); + const response = await axios.get(link); + const $ = cheerio.load(response.data); + + const list = $('tr.section') + .slice(0, 10) + .map(function() { + const info = { + title: $(this) + .find('td:nth-child(2) a') + .attr('title'), + link: $(this) + .find('td:nth-child(2) a') + .attr('href'), + date: $(this) + .find('td:nth-child(3)') + .text(), + }; + return info; + }) + .get(); + + const out = await Promise.all( + list.map(async (info) => { + const title = info.title; + const date = info.date; + const itemUrl = url.resolve(host, info.link); + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await axios.get(itemUrl); + const $ = cheerio.load(response.data); + + const single = { + title: title, + link: itemUrl, + description: $('.wp_articlecontent') + .html() + .replace(/src="\//g, `src="${url.resolve(host, '.')}`) + .trim(), + pubDate: new Date(date), + }; + ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: '南航计算机科学与技术学院学术讲座', + link: link, + description: '南航计算机科学与技术学院学术讲座RSS', + item: out, + }; +};