Skip to content

Commit

Permalink
feat(route): fix NUAA 教务处/计算机科学与技术学院信息 (#9361)
Browse files Browse the repository at this point in the history
* feat(route): fix NUAA 教务处/计算机科学与技术学院信息

* refactor: migrate to v2

* fix: deprecated url.resolve
  • Loading branch information
qrzbing authored Mar 24, 2022
1 parent 2ae88b7 commit f3618bb
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 225 deletions.
18 changes: 9 additions & 9 deletions docs/university.md
Original file line number Diff line number Diff line change
Expand Up @@ -1467,23 +1467,23 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS

## 南京航空航天大学

### 教务通知
### 教务处

<Route author="arcosx Seiry" example="/nuaa/jwc/default" path="/nuaa/jwc/:type" :paramsDesc="['分类名']">
<Route author="arcosx Seiry qrzbing" example="/nuaa/jwc/tzgg" path="/nuaa/jwc/:type/:getDescription?" :paramsDesc="['分类名', '是否获取描述']">

| 教学服务 | 教学建设 | 学生培养 | 教学资源 |
| ------------- | ---- | ---- | ---- |
| jxfw(default) | jxjs | xspy | jxzy |
| 通知公告 | 教学服务 | 教学建设 | 学生培养 | 教学资源 |
| ---- | ---- | ---- | ---- | ---- |
| tzgg | jxfw | jxjs | xspy | jxzy |

</Route>

### 计算机科学与技术学院

<Route author="LogicJake Seiry" example="/nuaa/cs/kydt" path="/nuaa/cs/:type?" :paramsDesc="['分类名']"/>
<Route author="LogicJake Seiry qrzbing" example="/nuaa/cs/jxdt" path="/nuaa/cs/:type/:getDescription?" :paramsDesc="['分类名', '是否获取描述']">

| 通知公告 | 新闻动态 | 科研动态 | 教学动态 | 学生工作 | 招生信息 | 就业信息 |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| tzgg | xwdt | kydt | jxdt | xsgz | zsxx | jyxx |
| 通知公告 | 热点新闻 | 学科科研 | 教学动态 | 本科生培养 | 研究生培养 | 学生工作 |
| ---- | ---- | ---- | ---- | ----- | ----- | ---- |
| tzgg | rdxw | xkky | jxdt | be | me | xsgz |

</Route>

Expand Down
8 changes: 4 additions & 4 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,10 @@ router.get('/seu/cse/:type?', lazyloadRouteHandler('./routes/universities/seu/cs
// 南京工业大学
router.get('/njtech/jwc', lazyloadRouteHandler('./routes/universities/njtech/jwc'));

// 南京航空航天大学
router.get('/nuaa/jwc/:type?', lazyloadRouteHandler('./routes/universities/nuaa/jwc/jwc'));
router.get('/nuaa/cs/:type?', lazyloadRouteHandler('./routes/universities/nuaa/cs/index'));
router.get('/nuaa/yjsy/:type?', lazyloadRouteHandler('./routes/universities/nuaa/yjsy/yjsy'));
// 南京航空航天大学 migrated to v2
// router.get('/nuaa/jwc/:type/:getDescription?', lazyloadRouteHandler('./routes/universities/nuaa/jwc/jwc'));
// router.get('/nuaa/cs/:type/:getDescription?', lazyloadRouteHandler('./routes/universities/nuaa/cs/index'));
// router.get('/nuaa/yjsy/:type?', lazyloadRouteHandler('./routes/universities/nuaa/yjsy/yjsy'));

// 河海大学
router.get('/hhu/libNews', lazyloadRouteHandler('./routes/universities/hhu/libNews'));
Expand Down
84 changes: 0 additions & 84 deletions lib/routes/universities/nuaa/cs/index.js

This file was deleted.

105 changes: 0 additions & 105 deletions lib/routes/universities/nuaa/jwc/jwc.js

This file was deleted.

87 changes: 87 additions & 0 deletions lib/v2/nuaa/cs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const getCookie = require('../utils/pypasswaf');
const host = 'http://cs.nuaa.edu.cn/';

const map = new Map([
['tzgg', { title: '南京航空航天大学计算机科学与技术学院 -- 通知公告', suffix: 'tzgg/list.htm' }],
['rdxw', { title: '南京航空航天大学计算机科学与技术学院 -- 热点新闻', suffix: '10846/list.htm' }],
['xkky', { title: '南京航空航天大学计算机科学与技术学院 -- 学科科研', suffix: '10849/list.htm' }],
['be', { title: '南京航空航天大学计算机科学与技术学院 -- 本科生培养', suffix: '10850/list.htm' }],
['me', { title: '南京航空航天大学计算机科学与技术学院 -- 研究生培养', suffix: '10851/list.htm' }],
['jxdt', { title: '南京航空航天大学计算机科学与技术学院 -- 教学动态', suffix: '1977/list.htm' }],
['xsgz', { title: '南京航空航天大学计算机科学与技术学院 -- 学生工作', suffix: '1959/list.htm' }],
]);

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

const link = new URL(suffix, host).href;
const cookie = await getCookie();
const gotConfig = {
headers: {
cookie,
},
};
const response = await got(link, gotConfig);
const $ = cheerio.load(response.data);

const list = $('#news_list ul li')
.slice(0, Math.min(parseInt($('.per_count', '#wp_paging_w6').text()), parseInt($('.all_count', '#wp_paging_w6').slice(1).text())))
.map(function () {
const info = {
title: $(this).find('a').attr('title'),
link: $(this).find('a').attr('href'),
date: $(this).find('span').text(),
};
return info;
})
.get();

const out = await Promise.all(
list.map((info) => {
const title = info.title || 'tzgg';
const date = info.date;
const itemUrl = new URL(info.link, host).href;

return ctx.cache.tryGet(itemUrl, async () => {
const arr = itemUrl.split('.');
const pageType = arr[arr.length - 1];

// 南航新 WAF 过于敏感
// 目前 description 需要遍历页面,会被 WAF 拦截导致无法输出
// 考虑换一种获取 description 的方式或者将标题当作 title。
let description = title;
if (getDescription) {
description = itemUrl;
if (pageType === 'htm' || pageType === 'html') {
const response = await got.get(itemUrl, gotConfig);
const $ = cheerio.load(response.data);
description = $('.wp_articlecontent')
.html()
.replace(/src="\//g, `src="${new URL('.', host).href}`)
.trim();
}
}

const single = {
title,
link: itemUrl,
description,
pubDate: parseDate(date),
};
return single;
});
})
);

ctx.state.data = {
title: map.get(type).title,
link,
description: '南京航空航天大学计算机科学与技术学院RSS',
item: out,
};
};
Loading

0 comments on commit f3618bb

Please sign in to comment.