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): id param for shmeea (DIYgod#14145)
* feat(route): id param for shmeea * fix(route): fix radar docs url in shmeea/self-study * fix(route): id?=08000 && block requests to binary files && fix code style ---------
- Loading branch information
1 parent
b13e3f6
commit 6e244aa
Showing
5 changed files
with
56 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,53 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const timezone = require('@/utils/timezone'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
module.exports = async (ctx) => { | ||
const baseURL = 'http://www.shmeea.edu.cn'; | ||
const rootUrl = baseURL + '/page/08000/index.html'; | ||
const response = await got({ | ||
method: 'get', | ||
url: rootUrl, | ||
}); | ||
const id = ctx.params.id ?? '08000'; | ||
const baseURL = 'https://www.shmeea.edu.cn'; | ||
const link = `${baseURL}/page/${id}/index.html`; | ||
|
||
const data = response.data; | ||
const response = await got(link); | ||
const $ = cheerio.load(response.data); | ||
|
||
const $ = cheerio.load(data); | ||
const title = `上海市教育考试院-${$('#main .pageh4-tit').text().trim()}`; | ||
|
||
const list = $('#main .pageList li'); | ||
const list = $('#main .pageList li') | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
return { | ||
title: item.find('a').attr('title') || item.find('a').text(), | ||
link: new URL(item.find('a').attr('href'), baseURL).href, | ||
pubDate: parseDate(item.find('.listTime').text().trim(), 'YYYY-MM-DD'), | ||
}; | ||
}); | ||
|
||
const items = await Promise.all( | ||
list.map(async (i, item) => { | ||
item = $(item); | ||
const link = baseURL + item.find('a').attr('href'); | ||
const description = await ctx.cache.tryGet(link, async () => { | ||
const result = await got.get(link); | ||
list.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
if (!item.link.endsWith('.html') || new URL(item.link).hostname !== new URL(baseURL).hostname) { | ||
return item; | ||
} | ||
|
||
const result = await got(item.link); | ||
const $ = cheerio.load(result.data); | ||
|
||
return $('#ivs_content').html(); | ||
}); | ||
return { | ||
title: item.find('a').text(), | ||
pubDate: new Date(item.find('.listTime').text()), | ||
link, | ||
description, | ||
}; | ||
}) | ||
const description = $('#ivs_content').html(); | ||
const pbTimeText = $('#ivs_title .PBtime').text().trim(); | ||
|
||
item.description = description; | ||
item.pubDate = pbTimeText ? timezone(parseDate(pbTimeText, 'YYYY-MM-DD HH:mm:ss'), +8) : item.pubDate; | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: '上海市教育考试院', | ||
description: '消息速递', | ||
link: baseURL, | ||
title, | ||
link, | ||
item: items, | ||
}; | ||
}; |
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,4 @@ | ||
module.exports = { | ||
'/': ['jialinghui'], | ||
'/:id?': ['jialinghui', 'Misaka13514'], | ||
'/self-study': ['h2ws'], | ||
}; |
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,4 @@ | ||
module.exports = function (router) { | ||
router.get('/', require('./index')); | ||
router.get('/self-study', require('./self-study')); | ||
router.get('/:id?', require('./index')); | ||
}; |
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