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): 西南交通大学教务网、扬华素质网 (DIYgod#12101)
* feat(route): 西南交通大学教务网、扬华素质网 * fix(route): fix wrong radar rule * docs: fix format * fix(route): format code style
- Loading branch information
Showing
6 changed files
with
183 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
const rootURL = 'http://jwc.swjtu.edu.cn'; | ||
const pageURL = `${rootURL}/vatuu/WebAction?setAction=newsList`; | ||
|
||
const getItem = (item, cache) => { | ||
const newsInfo = item.find('h3').find('a'); | ||
const newsTime = item.find('p').find('span').text().slice(0, 19); | ||
const newsTitle = newsInfo.text(); | ||
const link = `${rootURL}${newsInfo.attr('href').slice(2)}`; | ||
return cache.tryGet(link, async () => { | ||
try { | ||
const resp = await got({ | ||
method: 'get', | ||
url: link, | ||
}); | ||
const $$ = cheerio.load(resp.data); | ||
let newsText = $$('.content-main').html(); | ||
if (!newsText) { | ||
newsText = '转发通知'; | ||
} | ||
return { | ||
title: newsTitle, | ||
pubDate: parseDate(String(newsTime)), | ||
link, | ||
description: newsText, | ||
}; | ||
} catch (error) { | ||
if (error.response && error.response.status === 404) { | ||
return { | ||
title: newsTitle, | ||
pubDate: parseDate(String(newsTime)), | ||
link, | ||
description: '', | ||
}; | ||
} else { | ||
throw error; | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
module.exports = async (ctx) => { | ||
const resp = await got({ | ||
method: 'get', | ||
url: pageURL, | ||
}); | ||
|
||
const $ = cheerio.load(resp.data); | ||
const list = $("[class='littleResultDiv']"); | ||
|
||
const items = await Promise.all( | ||
list.toArray().map((i) => { | ||
const item = $(i); | ||
return getItem(item, ctx.cache); | ||
}) | ||
); | ||
|
||
ctx.state.data = { | ||
title: '西南交大-教务网通知', | ||
link: pageURL, | ||
item: items, | ||
allowEmpty: true, | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
module.exports = { | ||
'/jtys/yjs': ['qizidog'], | ||
'/jyzpxx': ['qizidog'], | ||
'/jwc': ['mobyw'], | ||
'/xg/:code?': ['mobyw'], | ||
}; |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
module.exports = function (router) { | ||
router.get('/jtys/yjs', require('./jtys/yjs')); | ||
router.get('/jyzpxx', require('./jyzpxx')); | ||
router.get('/jwc', require('./jwc')); | ||
router.get('/xg/:code?', require('./xg')); | ||
}; |
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,79 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
const rootURL = 'http://xg.swjtu.edu.cn'; | ||
const listURL = { | ||
tzgg: `${rootURL}/web/Home/PushNewsList?Lmk7LJw34Jmu=010j.shtml`, | ||
yhxw: `${rootURL}/web/Home/NewsList?LJw34Jmu=011e.shtml`, | ||
dcxy: `${rootURL}/web/Home/ColourfulCollegeNewsList`, | ||
xgzj: `${rootURL}/web/Home/NewsList?xvw34vmu=010e.shtml`, | ||
}; | ||
|
||
const getItem = (item, cache) => { | ||
const newsInfo = item.find('h4').find('a'); | ||
const newsTime = item.find('span.ctxlist-time').text(); | ||
const newsTitle = newsInfo.text(); | ||
const link = `${rootURL}${newsInfo.attr('href')}`; | ||
return cache.tryGet(link, async () => { | ||
try { | ||
const resp = await got({ | ||
method: 'get', | ||
url: link, | ||
}); | ||
const $$ = cheerio.load(resp.data); | ||
let newsText = $$('.detail-content-text').html(); | ||
if (!newsText) { | ||
newsText = '转发通知'; | ||
} | ||
return { | ||
title: newsTitle, | ||
pubDate: parseDate(String(newsTime)), | ||
link, | ||
description: newsText, | ||
}; | ||
} catch (error) { | ||
if (error.response && error.response.status === 404) { | ||
return { | ||
title: newsTitle, | ||
pubDate: parseDate(String(newsTime)), | ||
link, | ||
description: '', | ||
}; | ||
} else { | ||
throw error; | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
module.exports = async (ctx) => { | ||
const code = ctx.params.code ?? 'tzgg'; | ||
const pageURL = listURL[code]; | ||
|
||
if (!pageURL) { | ||
throw new Error('code not supported'); | ||
} | ||
|
||
const resp = await got({ | ||
method: 'get', | ||
url: pageURL, | ||
}); | ||
|
||
const $ = cheerio.load(resp.data); | ||
const list = $('div.right-side ul.block-ctxlist li'); | ||
|
||
const items = await Promise.all( | ||
list.toArray().map((i) => { | ||
const item = $(i); | ||
return getItem(item, ctx.cache); | ||
}) | ||
); | ||
|
||
ctx.state.data = { | ||
title: '西南交大-扬华素质网', | ||
link: pageURL, | ||
item: items, | ||
allowEmpty: true, | ||
}; | ||
}; |