feat: 增加 NOI 全国青少年信息学奥林匹克竞赛 (#3378)

This commit is contained in:
WenryXu
2019-11-04 14:35:22 +08:00
committed by DIYgod
parent ea292edd8c
commit db299b1983
3 changed files with 55 additions and 0 deletions

View File

@@ -65,6 +65,12 @@ pageClass: routes
<Route author="brilon" example="/mobdata/report" path="/mobdata/report"/>
## NOI 全国青少年信息学奥林匹克竞赛
### 新闻
<Route author="WenryXu" example="/noi" path="/noi"/>
## ONE · 一个
### 图片文字问答

View File

@@ -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;

46
lib/routes/noi/index.js Normal file
View File

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