From bca4b0e9160784f8dc01201c0b2f7e68131b5a42 Mon Sep 17 00:00:00 2001
From: nicolaszf <43488135+nicolaszf@users.noreply.github.com>
Date: Sun, 14 Jul 2019 22:47:06 -0500
Subject: [PATCH] =?UTF-8?q?feat:=20add=E9=87=8D=E5=BA=86=E5=A4=A7=E5=AD=A6?=
=?UTF-8?q?=E6=96=B0=E9=97=BB=E7=BD=91-=E5=AD=A6=E6=9C=AF=E9=A2=84?=
=?UTF-8?q?=E5=91=8A=20(#2617)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/university.md | 4 ++
lib/router.js | 1 +
lib/routes/universities/cqu/news/jzyg.js | 23 +++++++++++
lib/routes/universities/cqu/news/utils.js | 48 +++++++++++++++++++++++
4 files changed, 76 insertions(+)
create mode 100644 lib/routes/universities/cqu/news/jzyg.js
create mode 100644 lib/routes/universities/cqu/news/utils.js
diff --git a/docs/university.md b/docs/university.md
index c217d1955b..f378f22385 100644
--- a/docs/university.md
+++ b/docs/university.md
@@ -923,6 +923,10 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet
+### 新闻网讲座预告
+
+
+
## 重庆科技学院
### 教务处公告
diff --git a/lib/router.js b/lib/router.js
index af7ea5fc11..62b0391e9f 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -590,6 +590,7 @@ router.get('/heu/ugs/news/:author?/:category?', require('./routes/universities/h
// 重庆大学
router.get('/cqu/jwc/announcement', require('./routes/universities/cqu/jwc/announcement'));
+router.get('/cqu/news/jzyg', require('./routes/universities/cqu/news/jzyg'));
// 南京信息工程大学
router.get('/nuist/bulletin/:category?', require('./routes/universities/nuist/bulletin'));
diff --git a/lib/routes/universities/cqu/news/jzyg.js b/lib/routes/universities/cqu/news/jzyg.js
new file mode 100644
index 0000000000..c9a5bd8d52
--- /dev/null
+++ b/lib/routes/universities/cqu/news/jzyg.js
@@ -0,0 +1,23 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const util = require('./utils');
+
+module.exports = async (ctx) => {
+ const response = await got({
+ method: 'get',
+ url: 'http://news.cqu.edu.cn/newsv2/info-24.html',
+ });
+
+ const data = response.data;
+ const $ = cheerio.load(data);
+ const list = $('.item').get();
+
+ const result = await util.ProcessFeed(list, ctx.cache);
+
+ ctx.state.data = {
+ title: '重庆大学新闻网-讲座预告',
+ link: 'http://news.cqu.edu.cn/newsv2/info-24.html',
+ description: '重庆大学新闻网-讲座预告',
+ item: result,
+ };
+};
diff --git a/lib/routes/universities/cqu/news/utils.js b/lib/routes/universities/cqu/news/utils.js
new file mode 100644
index 0000000000..c7083b9768
--- /dev/null
+++ b/lib/routes/universities/cqu/news/utils.js
@@ -0,0 +1,48 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+
+// 加载文章页
+async function load(link) {
+ const response = await got.get(link);
+ const $ = cheerio.load(response.data);
+
+ // 提取内容
+ const description = $('.dinfo').html() + $('.acontent').html();
+
+ return { description };
+}
+
+const ProcessFeed = async (list, caches) =>
+ await Promise.all(
+ list.map(async (item) => {
+ const $ = cheerio.load(item);
+
+ const $title1 = $('.title a').eq(0);
+ const $title2 = $('.title a').eq(1);
+ let itemUrl = $title2.attr('href');
+ let title = $title1.text() + ' - ' + $title2.text();
+
+ if (typeof itemUrl === 'undefined') {
+ itemUrl = $title1.attr('href');
+ title = $title1.text();
+ }
+
+ // 列表上提取到的信息
+ const single = {
+ title: title,
+ link: itemUrl,
+ guid: itemUrl,
+ };
+
+ // 使用tryGet方法从缓存获取内容。
+ // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。
+ const other = await caches.tryGet(itemUrl, async () => await load(itemUrl));
+
+ // 合并解析后的结果集作为该篇文章最终的输出结果
+ return Promise.resolve(Object.assign({}, single, other));
+ })
+ );
+
+module.exports = {
+ ProcessFeed,
+};