diff --git a/assets/radar-rules.js b/assets/radar-rules.js index e5e8496c35..97020ec823 100644 --- a/assets/radar-rules.js +++ b/assets/radar-rules.js @@ -1372,6 +1372,18 @@ source: '/*', target: '/heu/yjsy/news', }, + { + title: '研究生院 - 国家公派项目', + docs: 'https://docs.rsshub.app/university.html#ha-er-bin-gong-cheng-da-xue', + source: '/*', + target: '/heu/yjsy/gjgp', + }, + { + title: '研究生院 - 国际合作与交流项目', + docs: 'https://docs.rsshub.app/university.html#ha-er-bin-gong-cheng-da-xue', + source: '/*', + target: '/heu/yjsy/gjhz', + }, ], uae: [ { @@ -1447,4 +1459,33 @@ }, ], }, + 'csc.edu.cn': { + _name: '国家留学网', + www: [ + { + title: '遴选通知', + docs: 'https://docs.rsshub.app/other.html#guo-jia-liu-xue-wang', + source: '/*', + target: '/csc/notice/lxtz', + }, + { + title: '综合项目专栏', + docs: 'https://docs.rsshub.app/other.html#guo-jia-liu-xue-wang', + source: '/*', + target: '/csc/notice/xmzl', + }, + { + title: '常见问题解答', + docs: 'https://docs.rsshub.app/other.html#guo-jia-liu-xue-wang', + source: '/*', + target: '/csc/notice/wtjd', + }, + { + title: '录取公告', + docs: 'https://docs.rsshub.app/other.html#guo-jia-liu-xue-wang', + source: '/*', + target: '/csc/notice/lqgg', + }, + ], + }, }); diff --git a/docs/other.md b/docs/other.md index a89706bfcd..4f54ae2615 100644 --- a/docs/other.md +++ b/docs/other.md @@ -236,6 +236,18 @@ type 为 all 时,category 参数不支持 cost 和 free +## 国家留学网 + +### 通知 + + + +| 遴选通知 | 综合项目专栏 | 常见问题解答 | 录取公告 | +| -------- | ------------ | ------------ | -------- | +| lxtz | xmzl | wtjd | lqgg | + + + ## 国家自然科学基金委员会 ### 新闻通知 diff --git a/docs/university.md b/docs/university.md index 1143e67a34..e9aa956d6e 100644 --- a/docs/university.md +++ b/docs/university.md @@ -387,11 +387,11 @@ category 列表: ### 研究生院 - + -| 通知公告 | 新闻动态 | -| ------------ | -------- | -| announcement | news | +| 通知公告 | 新闻动态 | 国家公派项目 | 国际合作与交流项目 | +| ------------ | -------- | ------------ | ------------------ | +| announcement | news | gjgp | gjhz | diff --git a/lib/router.js b/lib/router.js index b773a9f054..2161c6fe4b 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2333,4 +2333,7 @@ router.get('/yzu/yjszs/:type', require('./routes/universities/yzu/yjszs')); // 国家自然科学基金委员会 router.get('/nsfc/news/:type?', require('./routes/nsfc/news')); +// 国家留学网 +router.get('/csc/notice/:type?', require('./routes/csc/notice')); + module.exports = router; diff --git a/lib/routes/csc/notice.js b/lib/routes/csc/notice.js new file mode 100644 index 0000000000..68d3c26184 --- /dev/null +++ b/lib/routes/csc/notice.js @@ -0,0 +1,91 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const url = require('url'); +const iconv = require('iconv-lite'); + +const baseUrl = 'https://www.csc.edu.cn'; + +const typeMap = { + lxtz: { + name: '遴选通知', + url: '/chuguo/list/24', + }, + xmzl: { + name: '综合项目专栏', + url: '/chuguo/list/26', + }, + wtjd: { + name: '常见问题解答', + url: '/chuguo/list/27', + }, + lqgg: { + name: '录取公告', + url: '/chuguo/list/28', + }, +}; + +module.exports = async (ctx) => { + const type = ctx.params.type || 'jjyw'; + const link = baseUrl + typeMap[type].url; + const response = await got({ + method: 'get', + url: link, + headers: { + Referer: baseUrl, + }, + responseType: 'buffer', + }); + const responseHtml = iconv.decode(response.data, 'gbk'); + const $ = cheerio.load(responseHtml); + + const urlList = $('.list-a li') + .slice(0, 10) + .map((i, e) => $('a', e).attr('href')) + .get(); + + const titleList = $('.list-a li') + .slice(0, 10) + .map((i, e) => $('a', e).attr('title')) + .get(); + + const dateList = $('.list-a li') + .slice(0, 10) + .map((i, e) => $('span', e).text()) + .get(); + + const out = await Promise.all( + urlList.map(async (itemUrl, index) => { + itemUrl = url.resolve(baseUrl, itemUrl); + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + const response = await got({ + method: 'get', + url: itemUrl, + responseType: 'buffer', + }); + const responseHtmlItem = iconv.decode(response.data, 'gbk'); + const $ = cheerio.load(responseHtmlItem); + const single = { + title: titleList[index], + link: itemUrl, + description: $('.contents') + .html() + .replace(/src="\//g, `src="${url.resolve(baseUrl, '.')}`) + .replace(/href="\//g, `href="${url.resolve(baseUrl, '.')}`) + .trim(), + pubDate: dateList[index], + }; + ctx.cache.set(itemUrl, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: '国家留学网-' + typeMap[type].name, + link: link, + item: out, + }; +}; diff --git a/lib/routes/nsfc/news.js b/lib/routes/nsfc/news.js index bf3e561667..2579bd2ec0 100644 --- a/lib/routes/nsfc/news.js +++ b/lib/routes/nsfc/news.js @@ -2,7 +2,7 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const url = require('url'); -const baseUrl = 'http://www.nsfc.gov.cn/'; +const baseUrl = 'http://www.nsfc.gov.cn'; const typeMap = { jjyw: { diff --git a/lib/routes/universities/heu/yjsy.js b/lib/routes/universities/heu/yjsy.js index 647b2a7217..6d71d97303 100644 --- a/lib/routes/universities/heu/yjsy.js +++ b/lib/routes/universities/heu/yjsy.js @@ -13,6 +13,14 @@ const typeMap = { name: '新闻动态', url: '/2980/list.htm', }, + gjgp: { + name: '国家公派项目', + url: '/3015/list.htm', + }, + gjhz: { + name: '国际合作与交流项目', + url: '/3016/list.htm', + }, }; module.exports = async (ctx) => { @@ -77,7 +85,7 @@ module.exports = async (ctx) => { ); ctx.state.data = { - title: '哈尔滨工程大学研究生院' + typeMap[type].name, + title: '研究生院-' + typeMap[type].name, link: link, item: out, };