diff --git a/docs/README.md b/docs/README.md index b17f7debe..cc4bcf427 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1175,7 +1175,11 @@ category 列表: ### 南京理工大学 - + + + + + ### 四川旅游学院 diff --git a/router.js b/router.js index f5fae2bc4..9bfd77d1a 100644 --- a/router.js +++ b/router.js @@ -548,7 +548,9 @@ router.get('/cczu/jwc/:category?', require('./routes/universities/cczu/jwc')); router.get('/cczu/news/:category?', require('./routes/universities/cczu/news')); // 南京理工大学 -router.get('/njust', require('./routes/universities/njust/jwc')); +router.get('/njust/jwc/:type', require('./routes/universities/njust/jwc')); +router.get('/njust/cwc/:type', require('./routes/universities/njust/cwc')); +router.get('/njust/gs/:type', require('./routes/universities/njust/gs')); // 四川旅游学院 router.get('/sctu/xgxy', require('./routes/universities/sctu/xgxy')); diff --git a/routes/universities/njust/cwc/index.js b/routes/universities/njust/cwc/index.js new file mode 100644 index 000000000..6e8b3b8d7 --- /dev/null +++ b/routes/universities/njust/cwc/index.js @@ -0,0 +1,33 @@ +const axios = require('../../../../utils/axios'); +const cheerio = require('cheerio'); +const url = require('url'); + +const host = 'http://cwc.njust.edu.cn/'; + +const map = new Map([[1, { title: '南京理工大学财务处 -- 新闻及通知', id: 'wp_news_w2' }], [2, { title: '南京理工大学财务处 -- 办事指南', id: 'wp_news_w3' }]]); + +module.exports = async (ctx) => { + const type = Number.parseInt(ctx.params.type); + const response = await axios.get(host); + + const $ = cheerio.load(response.data); + + const id = map.get(type).id; + + const items = $(`#${id} tr tr`) + .map((_, elem) => { + const a = $('td:first-child > a', elem); + return { + link: url.resolve(host, a.attr('href')), + title: a.attr('title'), + pubDate: new Date($('td:nth-child(2)', elem).text()).toUTCString(), + }; + }) + .get(); + + ctx.state.data = { + link: host, + title: map.get(type).title, + item: items, + }; +}; diff --git a/routes/universities/njust/gs/index.js b/routes/universities/njust/gs/index.js new file mode 100644 index 000000000..ef976ffb3 --- /dev/null +++ b/routes/universities/njust/gs/index.js @@ -0,0 +1,40 @@ +const axios = require('../../../../utils/axios'); +const cheerio = require('cheerio'); + +const map = new Map([[1, { title: '南京理工大学研究生院 -- 博闻讲堂', id: '/sytzgg_4568' }], [2, { title: '南京理工大学研究生院 -- 学术公告', id: '/xshdggl' }]]); + +module.exports = async (ctx) => { + const type = Number.parseInt(ctx.params.type); + const id = map.get(type).id; + const baseURL = 'http://gs.njust.edu.cn'; + const res = await axios({ + method: 'get', + url: baseURL + id + '/list.htm', + headers: { + Referer: 'https://gs.njust.edu.cn/', + }, + }); + const data = res.data; + const $ = cheerio.load(data); + const list = $('.wp_article_list li'); + + ctx.state.data = { + title: '南京理工大学研究生网站', + link: 'https://gs.njust.edu.cn', + // description: '', + + item: + list && + list + .map((index, item) => { + item = $(item); + + return { + title: item.find('a').text(), + link: `${baseURL + $(item.find('a')).attr('href')}`, + pubDate: new Date(item.find('Article_PublishDate').text()).toUTCString(), + }; + }) + .get(), + }; +}; diff --git a/routes/universities/njust/jwc/index.js b/routes/universities/njust/jwc/index.js new file mode 100644 index 000000000..c44be382a --- /dev/null +++ b/routes/universities/njust/jwc/index.js @@ -0,0 +1,38 @@ +const axios = require('../../../../utils/axios'); +const cheerio = require('cheerio'); +const url = require('url'); + +const host = 'http://jwc.njust.edu.cn/'; + +const map = new Map([ + [1, { title: '南京理工大学教务处 -- 教师通知', id: 'wp_news_w12' }], + [2, { title: '南京理工大学教务处 -- 学生通知', id: 'wp_news_w13' }], + [3, { title: '南京理工大学教务处 -- 新闻', id: 'wp_news_w14' }], + [4, { title: '南京理工大学教务处 -- 学院动态', id: 'wp_news_w15' }], +]); + +module.exports = async (ctx) => { + const type = Number.parseInt(ctx.params.type); + const response = await axios.get(host); + + const $ = cheerio.load(response.data); + + const id = map.get(type).id; + + const items = $(`#${id} tr tr`) + .map((_, elem) => { + const a = $('td:first-child > a', elem); + return { + link: url.resolve(host, a.attr('href')), + title: a.attr('title'), + pubDate: new Date($('td:nth-child(2)', elem).text()).toUTCString(), + }; + }) + .get(); + + ctx.state.data = { + link: host, + title: map.get(type).title, + item: items, + }; +};