From 3efdea942ffc0cf3ad1a53ff576d6bfa22a91116 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 19 Dec 2020 00:51:52 +0800 Subject: [PATCH] feat: add a.m. turing award winners (#6459) --- docs/en/programming.md | 6 +++ docs/programming.md | 6 +++ lib/router.js | 3 ++ lib/routes/acm/amturingaward.js | 68 +++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 lib/routes/acm/amturingaward.js diff --git a/docs/en/programming.md b/docs/en/programming.md index 730c4a075b..e388ff8bc2 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 2a9e7a14ce..68a1c49496 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 a38fcbd0c2..2bfbf3d108 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 0000000000..297ea02988 --- /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, + }; +};