diff --git a/docs/university.md b/docs/university.md index 0342b4966..5d27e17d6 100644 --- a/docs/university.md +++ b/docs/university.md @@ -3138,6 +3138,16 @@ type 列表: +### 计算机学院 + + + +| 类型 | 学院新闻 | 通知公告 | 学术信息 | 学工动态 | 科研动态 | +| -- | ---- | ---- | ---- | ---- | ---- | +| 参数 | xyxw | tzgg | xsxx | xgdt | kydt | + + + ## 中山大学 ### 数据科学与计算机学院动态 diff --git a/lib/router.js b/lib/router.js index 1e71cd85a..82069b69a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -711,9 +711,6 @@ router.get('/hust/aia/notice/:type?', lazyloadRouteHandler('./routes/universitie // 井冈山大学 router.get('/jgsu/jwc', lazyloadRouteHandler('./routes/universities/jgsu/jwc')); -// 中南大学 -router.get('/csu/job/:type?', lazyloadRouteHandler('./routes/universities/csu/job')); - // 山东大学 migrated to v2 // router.get('/sdu/sc/:type?', lazyloadRouteHandler('./routes/universities/sdu/sc')); // router.get('/sdu/cs/:type?', lazyloadRouteHandler('./routes/universities/sdu/cs')); diff --git a/lib/v2/csu/cse.js b/lib/v2/csu/cse.js new file mode 100644 index 000000000..24b00b01c --- /dev/null +++ b/lib/v2/csu/cse.js @@ -0,0 +1,33 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +const fetch = require('./fetch_article'); + +module.exports = async (ctx) => { + const url = 'https://cse.csu.edu.cn/index/'; + const type = ctx.params.type ?? 'tzgg'; + const link = url + type + '.htm'; + const response = await got.get(link); + const $ = cheerio.load(response.data); + const list = $('.download li').get(); + const out = await Promise.all( + list.map((item) => { + const $ = cheerio.load(item); + const address = new URL($('a').attr('href'), url); + const title = $('a').text(); + const pubDate = $('span').text(); + return ctx.cache.tryGet(address, async () => { + const single = await fetch(address); + single.title = title; + single.pubDate = parseDate(pubDate, 'YYYY/MM/DD'); + return single; + }); + }) + ); + ctx.state.data = { + title: $('title').text(), + link, + item: out, + }; +}; diff --git a/lib/v2/csu/fetch_article.js b/lib/v2/csu/fetch_article.js new file mode 100644 index 000000000..78ff06ff7 --- /dev/null +++ b/lib/v2/csu/fetch_article.js @@ -0,0 +1,12 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); + +module.exports = async function fetch(address) { + const res = await got(address); + const $ = cheerio.load(res.data); + return { + description: $('[name="_newscontent_fromname"]').html(), + link: address, + guid: address, + }; +}; diff --git a/lib/routes/universities/csu/job.js b/lib/v2/csu/job.js similarity index 100% rename from lib/routes/universities/csu/job.js rename to lib/v2/csu/job.js diff --git a/lib/v2/csu/maintainer.js b/lib/v2/csu/maintainer.js new file mode 100644 index 000000000..747464c51 --- /dev/null +++ b/lib/v2/csu/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/cse/:type?': ['j1g5awi'], +}; diff --git a/lib/v2/csu/radar.js b/lib/v2/csu/radar.js new file mode 100644 index 000000000..c4a509152 --- /dev/null +++ b/lib/v2/csu/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'csu.edu.cn': { + _name: '中南大学', + cse: [ + { + title: '计算机学院', + docs: 'https://docs.rsshub.app/university.html#zhong-nan-da-xue', + source: ['/index/:type'], + target: (params) => `/csu/cse/${params.type.substring(0, 4)}`, + }, + ], + }, +}; diff --git a/lib/v2/csu/router.js b/lib/v2/csu/router.js new file mode 100644 index 000000000..c5ae3209e --- /dev/null +++ b/lib/v2/csu/router.js @@ -0,0 +1,4 @@ +module.exports = function (router) { + router.get('/cse/:type?', require('./cse')); + router.get('/job/:type?', require('./job')); +};