forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add 西安交大就业服务中心路由 (DIYgod#7783)
- Loading branch information
1 parent
568f58c
commit aa5a91f
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}) | ||
) | ||
), | ||
}; | ||
}; |