diff --git a/docs/en/other.md b/docs/en/other.md index 5fd2fa50e5..5bc5e6a04e 100644 --- a/docs/en/other.md +++ b/docs/en/other.md @@ -117,6 +117,18 @@ Official Website: [https://www.ssm.gov.mo/apps1/PreventWuhanInfection/en.aspx](h +## Nobel Prize + +### List + + + +| Physics | Chemistry | Physiology or Medicine | Literature | Peace | Economic Science | +| ------- | --------- | ---------------------- | ---------- | ----- | ----------------- | +| physics | chemistry | physiology-or-medicine | literature | peace | economic-sciences | + + + ## Parcel Tracking ### Hermes UK diff --git a/docs/other.md b/docs/other.md index 6822829170..36f6b48ad4 100644 --- a/docs/other.md +++ b/docs/other.md @@ -521,6 +521,18 @@ type 为 all 时,category 参数不支持 cost 和 free +## 诺贝尔奖 + +### 获奖名单 + + + +| 物理学 | 化学 | 生理学或医学 | 文学 | 和平 | 经济学 | +| ------- | --------- | ---------------------- | ---------- | ----- | ----------------- | +| physics | chemistry | physiology-or-medicine | literature | peace | economic-sciences | + + + ## 且听风吟福利 ### 分类 diff --git a/lib/router.js b/lib/router.js index 318892d625..5a85fd5881 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3240,6 +3240,9 @@ router.get('/appsales/:caty?/:time?', require('./routes/appsales/index')); // CGTN router.get('/cgtn/top', require('./routes/cgtn/top')); +// Nobel Prize +router.get('/nobelprize/:caty?', require('./routes/nobelprize/index')); + // 中華民國國防部 router.get('/gov/taiwan/mnd', require('./routes/gov/taiwan/mnd')); diff --git a/lib/routes/nobelprize/index.js b/lib/routes/nobelprize/index.js new file mode 100644 index 0000000000..c7a59b5066 --- /dev/null +++ b/lib/routes/nobelprize/index.js @@ -0,0 +1,79 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const config = { + physics: { + link: 'all-nobel-prizes-in-physics', + title: 'Physics', + }, + chemistry: { + link: 'all-nobel-prizes-in-chemistry', + title: 'Chemistry', + }, + 'physiology-or-medicine': { + link: 'all-nobel-laureates-in-physiology-or-medicine', + title: 'Physiology or Medicine', + }, + literature: { + link: 'all-nobel-prizes-in-literature', + title: 'Literature', + }, + peace: { + link: 'all-nobel-peace-prizes', + title: 'Peace', + }, + 'economic-sciences': { + link: 'all-prizes-in-economic-sciences', + title: 'Economic Science', + }, +}; + +module.exports = async (ctx) => { + let rootUrl = 'https://www.nobelprize.org/prizes/lists/all-nobel-prizes/'; + + const cfg = config[ctx.params.caty]; + if (cfg) { + rootUrl = `https://www.nobelprize.org/prizes/lists/${cfg.link}/`; + } + + const response = await got({ + method: 'get', + url: rootUrl, + }); + + const $ = cheerio.load(response.data); + + const items = $('div.by_year h3') + .map((_, item) => { + item = $(item); + if (item.text().length === 4) { + return Promise.resolve(''); + } + + const a = item.find('a'); + + let description = ''; + + item.nextAll().each(function () { + if ($(this).get(0).tagName === 'p') { + description += `

${$(this).html()}

`; + return true; + } + return false; + }); + + return { + title: a.text(), + link: a.attr('href'), + pubDate: new Date(`${a.text().match(/([0-9]{4})/)[1]}-01-01 00:00:00 GMT+0`).toUTCString(), + description, + }; + }) + .get(); + + ctx.state.data = { + title: $('title').eq(0).text(), + link: rootUrl, + item: items, + }; +};