feat(route): change csc to v2 (#8596)

This commit is contained in:
Derek
2021-11-27 23:31:07 +00:00
committed by GitHub
parent 8568686157
commit 7d858bc03d
6 changed files with 136 additions and 12 deletions
-9
View File
@@ -653,15 +653,6 @@
],
},
'apnews.com': { _name: 'AP News', '.': [{ title: '话题', docs: 'https://docs.rsshub.app/traditional-media.html#ap-news', source: '/:topic', target: '/apnews/topics/:topic' }] },
'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' },
],
},
'biquge5200.com': { www: [{ title: 'biquge5200.com', docs: 'https://docs.rsshub.app/reading.html#bi-qu-ge-biquge5200-com', source: '/:id', target: '/novel/biquge/:id' }] },
'biquge.info': { www: [{ title: 'biquge.info', docs: 'https://docs.rsshub.app/reading.html#bi-qu-ge-biquge-info', source: '/:id', target: '/novel/biqugeinfo/:id' }] },
'matters.news': {
-3
View File
@@ -2683,9 +2683,6 @@ router.get('/krankenkassen', lazyloadRouteHandler('./routes/krankenkassen'));
// 桂林航天工业学院
router.get('/guat/news/:type?', lazyloadRouteHandler('./routes/guat/news'));
// 国家留学网
router.get('/csc/notice/:type?', lazyloadRouteHandler('./routes/csc/notice'));
// LearnKu
router.get('/learnku/:community/:category?', lazyloadRouteHandler('./routes/learnku/topic'));
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/notice/:type?': ['Derekmini'],
};
+99
View File
@@ -0,0 +1,99 @@
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',
},
xwzx: {
name: '新闻资讯',
url: '/news',
},
xwgg: {
name: '新闻公告',
url: '/news/gonggao',
},
};
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,
item: out,
};
};
+31
View File
@@ -0,0 +1,31 @@
module.exports = {
'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',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/notice/:type?', require('./notice'));
};