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 }; +};