From db299b198340be41d82497afab5b6565d36f9e4c Mon Sep 17 00:00:00 2001 From: WenryXu Date: Mon, 4 Nov 2019 14:35:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20NOI=20=E5=85=A8?= =?UTF-8?q?=E5=9B=BD=E9=9D=92=E5=B0=91=E5=B9=B4=E4=BF=A1=E6=81=AF=E5=AD=A6?= =?UTF-8?q?=E5=A5=A5=E6=9E=97=E5=8C=B9=E5=85=8B=E7=AB=9E=E8=B5=9B=20(#3378?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/other.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/noi/index.js | 46 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 lib/routes/noi/index.js diff --git a/docs/other.md b/docs/other.md index 2e24890bba..208ef99345 100644 --- a/docs/other.md +++ b/docs/other.md @@ -65,6 +65,12 @@ pageClass: routes +## NOI 全国青少年信息学奥林匹克竞赛 + +### 新闻 + + + ## ONE · 一个 ### 图片文字问答 diff --git a/lib/router.js b/lib/router.js index 6e61d50763..de8306fc72 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1903,4 +1903,7 @@ router.get('/manong-weekly', require('./routes/manong-weekly/issues')); // 每日猪价 router.get('/pork-price', require('./routes/pork-price')); +// NOI 全国青少年信息学奥林匹克竞赛 +router.get('/noi', require('./routes/noi')); + module.exports = router; diff --git a/lib/routes/noi/index.js b/lib/routes/noi/index.js new file mode 100644 index 0000000000..52abb0a844 --- /dev/null +++ b/lib/routes/noi/index.js @@ -0,0 +1,46 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const response = await got({ + method: 'get', + url: `http://www.noi.cn/GetNews.dt?cmd=list&place=1&psize=20`, + }); + const result = await Promise.all( + Object.keys(response.data).map(async (key) => { + const item = response.data[key]; + if (item.id === undefined) { + return true; + } + const title = (item.title + ' ' + item.title2).trim(); + const link = 'http://www.noi.cn/newsview.html?id=' + item.id + '&hash=' + item.hash; + const guid = item.id + '_' + item.mtime; + const pubDate = new Date(item.mtime).toUTCString(); + + const single = { + title: title, + link: link, + guid: guid, + pubDate: pubDate, + description: '', + }; + + const description_key = 'noi' + guid; + const description_value = await ctx.cache.get(description_key); + + if (description_value) { + single.description = description_value; + } else { + const url = 'http://www.noi.cn/GetNews.dt?cmd=read&newsid=' + item.id + '&hash=' + item.hash; + const temp = await got({ + method: 'get', + url: url, + }); + single.description = temp.data.cont; + ctx.cache.set(description_key, single.description); + } + + return Promise.resolve(single); + }) + ); + ctx.state.data = { title: 'NOI 全国青少年信息学奥林匹克竞赛', link: 'http://www.noi.cn/', item: result }; +};