Skip to content

Commit

Permalink
feat(route): add 西安交大就业服务中心路由 (DIYgod#7783)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanXie123 authored Jul 9, 2021
1 parent 568f58c commit aa5a91f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/university.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

## 西北工业大学

### 翱翔门户
Expand Down
1 change: 1 addition & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
51 changes: 51 additions & 0 deletions lib/routes/universities/xjtu/job.js
Original file line number Diff line number Diff line change
@@ -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;
})
)
),
};
};

0 comments on commit aa5a91f

Please sign in to comment.