diff --git a/docs/README.md b/docs/README.md index 7f2e54f53..3d14dfc36 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1539,6 +1539,16 @@ category 列表: 注意: `qttz` 与 `xwdt` 在原网站等价. + +### 华南理工大学 + + + +| 教务通知 | 交流交换 | 新闻动态 | 媒体关注 | 学院通知 | +| -------- | -------- | -------- | -------- | -------- | +| 1 | 2 | 3 | 4 | 5 | + + ## 传统媒体 diff --git a/router.js b/router.js index a3bed7d79..d6e9cade8 100644 --- a/router.js +++ b/router.js @@ -627,6 +627,9 @@ router.get('/dgut/xsc/:type?', require('./routes/universities/dgut/xsc')); // 同济大学 router.get('/tju/sse/:type?', require('./routes/universities/tju/sse/notice')); +// 华南理工大学 +router.get('/scut/jwc/:category?', require('./routes/universities/scut/jwc')); + // ifanr router.get('/ifanr/:channel?', require('./routes/ifanr/index')); diff --git a/routes/universities/scut/jwc.js b/routes/universities/scut/jwc.js new file mode 100644 index 000000000..99feb2d9f --- /dev/null +++ b/routes/universities/scut/jwc.js @@ -0,0 +1,70 @@ +const axios = require('../../../utils/axios'); +const cheerio = require('cheerio'); +const url = require('url'); +const qs = require('querystring'); + +const baseUrl = 'http://jwc.scuteo.com/'; + +const categoryMap = { + '1': { title: '教务通知', id: 'f25701314e90988c014e90ad57500004' }, + '2': { title: '交流交换', id: 'ff8080815bc6f38d015bd27cc8d8001d' }, + '3': { title: '新闻动态', id: '8a8a8a5d4ed24d4a014ed26f32600000' }, + '4': { title: '媒体关注', id: '8a8a8a5d4ed27047014ed272fb000001' }, + '5': { title: '学院通知', id: '8a8a8a5d4ed27047014ed2729a770000' }, +}; + +module.exports = async (ctx) => { + const category = ctx.params.category || '1'; + const categoryData = categoryMap[category]; + + const listLink = baseUrl + 'jiaowuchu/cms/category/index.do?id=' + categoryData.id; + const listResponse = await axios({ + method: 'post', + url: baseUrl + 'jiaowuchu/cms/category/index.do', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + data: qs.stringify({ + id: categoryData.id, + offset: 0, + pagesize: 20, + }), + }); + + const itemList = listResponse.data.results; + const out = await Promise.all( + itemList.map(async (itemData) => { + const itemUrl = url.resolve(baseUrl, 'jiaowuchu' + itemData.href); + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const itemResponse = await axios.get(itemUrl); + const $ = cheerio.load(itemResponse.data); + const desc = $('.department-content-detail'); + const item = { + title: itemData.title, + link: itemUrl, + description: + desc.length > 0 + ? desc + .html() + .replace(/src="\//g, `src="${url.resolve(baseUrl, '.')}`) + .replace(/href="\//g, `href="${url.resolve(baseUrl, '.')}`) + .trim() + : null, + pubDate: itemData.date, + }; + + ctx.cache.set(itemUrl, JSON.stringify(item), 24 * 60 * 60); + return Promise.resolve(item); + }) + ); + + ctx.state.data = { + title: '华南理工大学教务处 - ' + categoryData.title, + link: listLink, + item: out, + }; +};