-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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 chsi/hotnews (#12154)
* feat(route): add chsi/hotnews * feat(route): add chsi/hotnews * add pubDate , not need timezone * add pubDate , not need timezone * add pubDate if $('.news-time').text() --------- Co-authored-by: 牛鑫语 <niuxinyu@szbit.cn>
- Loading branch information
Showing
5 changed files
with
81 additions
and
13 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,56 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
const host = 'https://yz.chsi.com.cn'; | ||
|
||
module.exports = async (ctx) => { | ||
const response = await got(host); | ||
const $ = cheerio.load(response.data); | ||
const list = $('.focus-part .index-hot a'); | ||
const items = await Promise.all( | ||
list.map((i, item) => { | ||
const { href: path, title: itemTitle } = item.attribs; | ||
let itemUrl = ''; | ||
if (path.startsWith('http')) { | ||
itemUrl = path; | ||
} else { | ||
itemUrl = host + path; | ||
} | ||
return ctx.cache.tryGet(itemUrl, async () => { | ||
let description = ''; | ||
let itemDate = undefined; | ||
if (path) { | ||
const result = await got(itemUrl); | ||
const $ = cheerio.load(result.data); | ||
if ($('#article_dnull').html()) { | ||
description = $('#article_dnull').html().trim(); | ||
} else { | ||
description = itemTitle; | ||
} | ||
if ($('.news-time').text()) { | ||
itemDate = $('.news-time').text(); | ||
} | ||
} else { | ||
description = itemTitle; | ||
} | ||
const result = { | ||
title: itemTitle, | ||
link: itemUrl, | ||
description, | ||
}; | ||
if (itemDate) { | ||
result.pubDate = parseDate(itemDate, 'YYYY年MM月DD日'); | ||
} | ||
return result; | ||
}); | ||
}) | ||
); | ||
|
||
ctx.state.data = { | ||
title: `中国研究生招生信息网 - 热点`, | ||
link: host, | ||
description: '中国研究生招生信息网 - 热点', | ||
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,3 +1,4 @@ | ||
module.exports = { | ||
'/hotnews': ['yanbot-team'], | ||
'/kydt': ['SunBK201'], | ||
}; |
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,3 +1,4 @@ | ||
module.exports = (router) => { | ||
router.get('/hotnews', require('./hotnews')); | ||
router.get('/kydt', require('./kydt')); | ||
}; |