feat(route): add 西安交大就业服务中心路由 (#7783)

This commit is contained in:
DylanXie123
2021-07-09 23:19:44 +08:00
committed by GitHub
parent 568f58c11c
commit aa5a91fa05
3 changed files with 62 additions and 0 deletions

View File

@@ -1922,6 +1922,16 @@ type 列表:
<Route author="nczitzk" example="/xjtu/gs/tzgg" path="/xjtu/gs/tzgg" />
### 就业创业中心
<Route author="DylanXie123" example="/xjtu/job/xdsgwy" path="/xjtu/job/:subpath?" :paramsDesc="['栏目类型,默认请求`zxtg`,详见下方表格']" />
栏目类型
| 中心通告 | 选调生及公务员 | 国际组织实习 | 新闻资讯 | 活动与讲座 |
| -------- | -------------- | ------------ | -------- | ---------- |
| zxtg | xdsgwy | gjzzsx | xwzx | hdyjz |
## 西北工业大学
### 翱翔门户

View File

@@ -2651,6 +2651,7 @@ router.get('/wolley/host/:host', require('./routes/wolley/host'));
router.get('/xjtu/gs/tzgg', require('./routes/universities/xjtu/gs/tzgg'));
router.get('/xjtu/dean/:subpath+', require('./routes/universities/xjtu/dean'));
router.get('/xjtu/international/:subpath+', require('./routes/universities/xjtu/international'));
router.get('/xjtu/job/:subpath?', require('./routes/universities/xjtu/job'));
// booksource
router.get('/booksource', require('./routes/booksource/index'));

View File

@@ -0,0 +1,51 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const subpath = ctx.params.subpath || 'zxtg';
const arr = {
zxtg: '中心通告',
xdsgwy: '选调生|公务员',
gjzzsx: '国际组织实习',
xwzx: '新闻资讯',
hdyjz: '活动与讲座',
};
const rootUrl = `https://job.xjtu.edu.cn/news.do;?ext=${arr[subpath]}`;
const baseUrl = 'https://job.xjtu.edu.cn';
const list_response = await got.get(rootUrl);
const $ = cheerio.load(list_response.data);
const list = $('div.jsnr ul li')
.slice(0, 10)
.map((_, item) => {
item = $(item);
const a = item.find('a');
return {
title: a.find('span').text(),
link: new URL(a.attr('href'), baseUrl),
};
})
.get();
ctx.state.data = {
title: `西安交通大学就业网-${arr[subpath]}`,
link: baseUrl,
item: await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const res = await got.get(item.link);
const content = cheerio.load(res.data);
item.description = content('div.jsnr').html();
const dateStr = content('div.jsnrly span').eq(1).text();
const date = parseDate(dateStr, 'YYYY MM DD HH mm', 'zh-cn');
item.pubDate = timezone(date, +8);
return item;
})
)
),
};
};