feat: add 暨南大学 JNU (#5762)

This commit is contained in:
Jonathan Goh 2020-10-03 07:31:39 +08:00 committed by GitHub
parent 41b31925be
commit 0c30c886ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 143 additions and 0 deletions

View File

@ -454,6 +454,24 @@ xskb1 对应 <http://www.auto.uestc.edu.cn/index/xskb1.htm>
<Route author="sushengmao" example="/gzyjs" path="/gzyjs" />
## 暨南大学
## 暨南要闻
<Route author="hang333" example="/jnu/yw/tt" path="/jnu/yw/:type?" :paramDesc="['暨南要闻类型,默认为 `yw`']">
| 暨大头条 | 暨南要闻 |
| -------- | -------- |
| tt | yw |
### 暨南大学校园时讯
<Route author="hang333" example="/jnu/xysx/yxsd" path="/jnu/xysx/:type" :paramDesc="['校园时讯类型']">
| 院系速递 | 部门快讯 |
| -------- | -------- |
| yxsd | bmkx |
## 桂林电子科技大学
### 新闻资讯

View File

@ -2590,6 +2590,10 @@ router.get('/sustyjs', require('./routes/universities/sustyjs/sustyjs'));
// 广州大学
router.get('/gzyjs', require('./routes/universities/gzyjs/gzyjs'));
// 暨南大学
router.get('/jnu/xysx/:type', require('./routes/universities/jnu/xysx/index'));
router.get('/jnu/yw/:type?', require('./routes/universities/jnu/yw/index'));
// 深圳大学
router.get('/szuyjs', require('./routes/universities/szuyjs/szuyjs'));

View File

@ -0,0 +1,40 @@
const got = require('@/utils/got');
const url = require('url');
const cheerio = require('cheerio');
const xysxUrl = 'https://news.jnu.edu.cn/xysx/';
const xysxType = { yxsd: '院系速递', bmkx: '部门快讯' };
module.exports = async (ctx) => {
const type = ctx.params.type;
// 发起 HTTP GET 请求
const response = await got({
method: 'get',
headers: {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36',
},
url: `${xysxUrl}${type}/`,
});
const $ = cheerio.load(response.data);
const list = $('ul[class=newsConList] > li')
.map(function () {
const info = {
title: $(this).find('div[class=title] > a').text(),
link: url.resolve(xysxUrl, $(this).find('div[class=title] > a').attr('href')),
description: $(this).find('div[class=intro]').text(),
pubDate: new Date($(this).find('div[class=date]').text()).toUTCString(),
};
return info;
})
.get();
const desc = `暨南大学校园时讯 - ${xysxType[type]}`;
ctx.state.data = {
title: desc,
description: desc,
link: `${xysxUrl}${type}/`,
item: list,
};
};

View File

@ -0,0 +1,81 @@
const got = require('@/utils/got');
const url = require('url');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const type = ctx.params.type || 'yw';
const ywUrl = type !== 'tt' ? 'https://news.jnu.edu.cn/jnyw/List/List_149.html' : 'https://news.jnu.edu.cn/jnyw/jdtt/';
// 发起 HTTP GET 请求
const response = await got({
method: 'get',
headers: {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36',
},
url: `${ywUrl}`,
});
const $ = cheerio.load(response.data);
if (type === 'tt') {
// 暨大头条
const list = $('ul[class=newsConList] > li')
.map(function () {
const info = {
title: $(this).find('div[class=title] > a').text(),
link: url.resolve(ywUrl, $(this).find('div[class=title] > a').attr('href')),
description: $(this).find('div[class=intro]').text(),
pubDate: new Date($(this).find('div[class=date]').text()).toUTCString(),
};
return info;
})
.get();
const desc = '暨大头条';
ctx.state.data = {
title: desc,
description: desc,
link: `${ywUrl}`,
item: list,
};
} else {
// 暨南要闻
const list = $('ul[class="newsList infoList infoListA"] > li')
.map(function () {
const info = {
title: $(this).find('a').text(),
link: $(this).find('a').attr('href'),
description: '',
pubDate: new Date($(this).find('span[class=date]').text()).toUTCString(),
};
return info;
})
.get();
const out = await Promise.all(
list
.filter((item) => item.link)
.map(async (item) => {
const itemUrl = url.resolve(ywUrl, item.link);
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await got.get(itemUrl);
const $ = cheerio.load(response.data);
item.description = $('div[class=conTxt]').html();
ctx.cache.set(itemUrl, JSON.stringify(item));
return Promise.resolve(item);
})
);
const desc = '暨南要闻';
ctx.state.data = {
title: desc,
description: desc,
link: `${ywUrl}`,
item: out,
};
}
};