Skip to content

Commit

Permalink
feat: add 扬州大学 (#4133)
Browse files Browse the repository at this point in the history
  • Loading branch information
LogicJake committed Mar 2, 2020
1 parent 6ccc9ba commit 8b0a6ff
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/university.md
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,28 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet

</Route>

## 扬州大学

### 官网消息

<Route author="LogicJake" example="/yzu/home/xxyw" path="/universities/yzu/home/:type" :paramsDesc="['分类名']">

| 学校要闻 | 校园新闻 | 信息公告 | 学术活动 | 媒体扬大 |
| -------- | -------- | -------- | -------- | -------- |
| xxyw | xyxw | xxgg | xshd | mtyd |

</Route>

### 研究生招生

<Route author="LogicJake" example="/yzu/yjszs/tzgg" path="/universities/yzu/yjszs/:type" :paramsDesc="['分类名']">

| 通知公告 | 博士招生 | 硕士招生 |
| -------- | -------- | -------- |
| tzgg | bszs | sszs |

</Route>

## 浙江大学

### 普通栏目 如学术/图片/新闻等
Expand Down
4 changes: 4 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2316,4 +2316,8 @@ router.get('/blogs/hedwig/:type', require('./routes/blogs/hedwig'));
// LoveHeaven
router.get('/loveheaven/update/:slug', require('./routes/loveheaven/update'));

// 扬州大学
router.get('/yzu/home/:type', require('./routes/universities/yzu/home'));
router.get('/yzu/yjszs/:type', require('./routes/universities/yzu/yjszs'));

module.exports = router;
83 changes: 83 additions & 0 deletions lib/routes/universities/yzu/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');
const host = 'http://www.yzu.edu.cn/';

const map = new Map([
['xxyw', { title: '扬州大学 -- 学校要闻', suffix: 'col/col37745/index.html', id: 37745 }],
['xyxw', { title: '扬州大学 -- 校园新闻', suffix: 'col/col37746/index.html', id: 37746 }],
['xxgg', { title: '扬州大学 -- 信息公告', suffix: 'col/col37747/index.html', id: 37747 }],
['xshd', { title: '扬州大学 -- 学术活动', suffix: 'col/col37748/index.html', id: 37748 }],
['mtyd', { title: '扬州大学 -- 媒体扬大', suffix: 'col/col45661/index.html', id: 45661 }],
]);

module.exports = async (ctx) => {
const type = ctx.params.type;
const suffix = map.get(type).suffix;

const link = url.resolve(host, suffix);
const response = await got({
method: 'post',
url: 'http://www.yzu.edu.cn/module/web/jpage/dataproxy.jsp?startrecord=1&endrecord=10&perpage=10',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
Accept: 'application/xml',
},
data: `columnid=${map.get(type).id}&unitid=54996`,
});
const $ = cheerio.load(response.data, { xmlMode: true });

const list = $('record')
.slice(0, 10)
.map(function() {
const $$ = cheerio.load($(this).html());
const info = {
title: $$('a').attr('title'),
link: $$('a').attr('href'),
date: $$('span').text(),
};
return info;
})
.get();

const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const date = info.date;
const itemUrl = url.resolve(host, info.link);

const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}

let description;
if (itemUrl.indexOf('yzu.edu.cn/art') !== -1) {
const response = await got.get(itemUrl);
const $ = cheerio.load(response.data);
description = $('#zoom')
.html()
.replace(/src="\//g, `src="${url.resolve(host, '.')}`)
.trim();
} else {
description = '站外链接无法抓取全文';
}

const single = {
title: title,
link: itemUrl,
description: description,
pubDate: new Date(date).toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
})
);

ctx.state.data = {
title: map.get(type).title,
link: link,
description: '扬州大学 RSS',
item: out,
};
};
81 changes: 81 additions & 0 deletions lib/routes/universities/yzu/yjszs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');
const host = 'http://yjszs.yzu.edu.cn/';

const map = new Map([
['tzgg', { title: '扬州大学研究生招生 -- 通知公告', suffix: 'col/col37091/index.html', id: 37091 }],
['bszs', { title: '扬州大学研究生招生 -- 博士招生', suffix: 'col/col37129/index.html', id: 37129 }],
['sszs', { title: '扬州大学研究生招生 -- 硕士招生', suffix: 'col/col37130/index.html', id: 37130 }],
]);

module.exports = async (ctx) => {
const type = ctx.params.type;
const suffix = map.get(type).suffix;

const link = url.resolve(host, suffix);
const response = await got({
method: 'post',
url: 'http://yjszs.yzu.edu.cn/module/web/jpage/dataproxy.jsp?startrecord=1&endrecord=10&perpage=10',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
Accept: 'application/xml',
},
data: `columnid=${map.get(type).id}&unitid=54996`,
});
const $ = cheerio.load(response.data, { xmlMode: true });

const list = $('record')
.slice(0, 10)
.map(function() {
const $$ = cheerio.load($(this).html());
const info = {
title: $$('a').attr('title'),
link: $$('a').attr('href'),
date: $$('span').text(),
};
return info;
})
.get();

const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const date = info.date;
const itemUrl = url.resolve(host, info.link);

const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}

let description;
if (itemUrl.indexOf('yzu.edu.cn/art') !== -1) {
const response = await got.get(itemUrl);
const $ = cheerio.load(response.data);
description = $('#zoom')
.html()
.replace(/src="\//g, `src="${url.resolve(host, '.')}`)
.trim();
} else {
description = '站外链接无法抓取全文';
}

const single = {
title: title,
link: itemUrl,
description: description,
pubDate: new Date(date).toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
})
);

ctx.state.data = {
title: map.get(type).title,
link: link,
description: '扬州大学研究生招生 RSS',
item: out,
};
};

0 comments on commit 8b0a6ff

Please sign in to comment.