From 058a5ee5f3a6b5cda132f4620f98ac9fa609d0cc Mon Sep 17 00:00:00 2001
From: TrumanGu <32283973+TrumanGu@users.noreply.github.com>
Date: Thu, 25 Jul 2019 11:27:58 +0800
Subject: [PATCH] feat: add njtech jwc (#2682)
* feat: add njtech jwc
* style: format code style
---
docs/university.md | 6 +++
lib/router.js | 3 ++
lib/routes/universities/njtech/jwc.js | 56 +++++++++++++++++++++++++++
3 files changed, 65 insertions(+)
create mode 100644 lib/routes/universities/njtech/jwc.js
diff --git a/docs/university.md b/docs/university.md
index 298dba03a..c36870db0 100644
--- a/docs/university.md
+++ b/docs/university.md
@@ -954,3 +954,9 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet
### 数据科学与计算机学院动态
+
+## 南京工业大学
+
+### 南京工业大学教务处
+
+
diff --git a/lib/router.js b/lib/router.js
index 6cb7289de..2f32d6e44 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -534,6 +534,9 @@ router.get('/seu/radio/academic', require('./routes/universities/seu/radio/acade
router.get('/seu/yzb/:type', require('./routes/universities/seu/yzb'));
router.get('/seu/cse/:type?', require('./routes/universities/seu/cse'));
+// 南京工业大学
+router.get('/njtech/jwc', require('./routes/universities/njtech/jwc'));
+
// 南京航空航天大学
router.get('/nuaa/jwc/:type?', require('./routes/universities/nuaa/jwc/jwc'));
router.get('/nuaa/cs/:type?', require('./routes/universities/nuaa/cs/index'));
diff --git a/lib/routes/universities/njtech/jwc.js b/lib/routes/universities/njtech/jwc.js
new file mode 100644
index 000000000..efce1e61e
--- /dev/null
+++ b/lib/routes/universities/njtech/jwc.js
@@ -0,0 +1,56 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+
+const host = 'http://jwb.njtech.edu.cn';
+
+const link = host + '/index/tzgg.htm';
+
+module.exports = async (ctx) => {
+ const response = await got({
+ method: 'get',
+ url: link,
+ headers: {
+ Referer: host,
+ },
+ });
+
+ const $ = cheerio.load(response.data);
+
+ const urlList = $('#mainRight li a')
+ .get()
+ .map(
+ (i) =>
+ host +
+ $(i)
+ .attr('href')
+ .replace('..', '')
+ );
+
+ const out = await Promise.all(
+ urlList.map(async (itemUrl) => {
+ const cache = await ctx.cache.get(itemUrl);
+ if (cache) {
+ return Promise.resolve(JSON.parse(cache));
+ }
+ const response = await got.get(itemUrl);
+ const $ = cheerio.load(response.data);
+ const single = {
+ title: $('#mainRight .title').text(),
+ link: itemUrl,
+ description: $('#vsb_content').html(),
+ pubDate: $('.time')
+ .text()
+ .match(/(\d{4}-\d{2})-\d{2}/)[0],
+ };
+ ctx.cache.set(itemUrl, JSON.stringify(single));
+ return Promise.resolve(single);
+ })
+ );
+ const info = '教务公告';
+
+ ctx.state.data = {
+ title: '南京工业大学教务处 - ' + info,
+ link,
+ item: out,
+ };
+};