diff --git a/docs/en/programming.md b/docs/en/programming.md index 730c4a075..e388ff8bc 100644 --- a/docs/en/programming.md +++ b/docs/en/programming.md @@ -4,6 +4,12 @@ pageClass: routes # Programming +## ACM + +### A.M.Turing Award Winners + + + ## cve.mitre.org ### Search Result diff --git a/docs/programming.md b/docs/programming.md index 2a9e7a14c..68a1c4949 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -4,6 +4,12 @@ pageClass: routes # 编程 +## ACM + +### 图灵奖获得者 + + + ## AI 研习社 ### 首页 diff --git a/lib/router.js b/lib/router.js index a38fcbd0c..2bfbf3d10 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3716,4 +3716,7 @@ router.get('/craigslist/:location/:type', require('./routes/craigslist/search')) // 有趣天文奇观 router.get('/interesting-sky', require('./routes/interesting-sky/index')); +// ACM +router.get('/acm/amturingaward', require('./routes/acm/amturingaward')); + module.exports = router; diff --git a/lib/routes/acm/amturingaward.js b/lib/routes/acm/amturingaward.js new file mode 100644 index 000000000..297ea0298 --- /dev/null +++ b/lib/routes/acm/amturingaward.js @@ -0,0 +1,68 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const rootUrl = 'https://amturing.acm.org'; + const currentUrl = `${rootUrl}/byyear.cfm`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const items = await Promise.all( + $('.award-winners-list li') + .slice(0, 5) + .map(async (_, item) => { + item = $(item); + + const year = item.find('span').text().replace(/\(|\)/g, ''); + const pubDate = new Date(`${year}-12-31`).toUTCString(); + + const winnersUrls = []; + let winnerResponses = []; + + item.find('a').each(function () { + winnersUrls.push(`${rootUrl}${$(this).attr('href')}`); + }); + + winnerResponses = winnersUrls.map((url) => + got({ + method: 'get', + url, + }) + ); + + const description = await Promise.all(winnerResponses).then((winners) => { + let winnerDescription = ''; + + for (const winner of winners) { + const content = cheerio.load(winner.data); + const image = content('.featured-photo').html(); + const column = content('#tertiary-navigation').parent(); + + content('#tertiary-navigation').remove(); + + winnerDescription += image + column.html(); + } + + return Promise.resolve(winnerDescription); + }); + + return { + pubDate, + description, + title: year, + link: currentUrl, + }; + }) + .get() + ); + + ctx.state.data = { + title: 'A.M. Turing Award Winners', + link: currentUrl, + item: items, + }; +};