From 087699ff5f6c2bca920d72c59b6b825ec90ad25a Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Wed, 19 Aug 2020 04:08:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E6=90=9C=E9=9F=B5=E7=BD=91?= =?UTF-8?q?=E8=AF=97=E8=AF=8D=E6=97=A5=E5=8E=86=20(#5430)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Henry Wang --- docs/study.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/souyun/today.js | 40 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 lib/routes/souyun/today.js diff --git a/docs/study.md b/docs/study.md index 55067c1a8c..7c29cf4010 100644 --- a/docs/study.md +++ b/docs/study.md @@ -172,6 +172,12 @@ pageClass: routes +## 搜韵网 + +### 诗词日历 + + + ## 网易公开课 ### 精品课程 diff --git a/lib/router.js b/lib/router.js index c9a60cb41c..6df252945b 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3061,6 +3061,9 @@ router.get('/telecompaper/news/:caty/:year?/:country?/:type?/:keyword?', require // 水木社区 router.get('/newsmth/account/:id', require('./routes/newsmth/account')); +// 搜韵网 +router.get('/souyun/today', require('./routes/souyun/today')); + // 生物谷 router.get('/bioon/latest', require('./routes/bioon/latest')); diff --git a/lib/routes/souyun/today.js b/lib/routes/souyun/today.js new file mode 100644 index 0000000000..705cd367ef --- /dev/null +++ b/lib/routes/souyun/today.js @@ -0,0 +1,40 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const currentUrl = 'https://sou-yun.cn/AncientToday.aspx'; + const poemUrl = 'https://api.sou-yun.cn/api/RecommendedReading?type=poem&needHtml=true'; + const wordUrl = 'https://api.sou-yun.cn/api/RecommendedReading?type=word'; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const poemResponse = await got({ + method: 'get', + url: poemUrl, + }); + + const wordResponse = await got({ + method: 'get', + url: wordUrl, + }); + + const $ = cheerio.load(response.data); + const birthday = $('span.titleHint').parent().html(); + const today = $('input[name="LastSelectedDate"]').attr('value'); + + ctx.state.data = { + title: '搜韵网 - 诗词日历', + link: currentUrl, + item: [ + { + title: poemResponse.data.Date, + link: currentUrl, + description: poemResponse.data.Content.Text + '
' + birthday + '
' + wordResponse.data.Content.Text, + pubDate: new Date(today + ' GMT+8').toUTCString(), + }, + ], + }; +};