diff --git a/docs/README.md b/docs/README.md index a56dd02bd..6e41f57fb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2163,3 +2163,7 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运 1. 复制查询结果 URL 中`?`后的部分,例如 `https://www.autotrader.co.uk/car-search?radius=50&postcode=sw1a1aa&onesearchad=Used&onesearchad=Nearly%20New&onesearchad=New&price-to=9000&year-from=2012&body-type=Hatchback&transmission=Automatic&exclude-writeoff-categories=on` 则为 `radius=50&postcode=sw1a1aa&onesearchad=Used&onesearchad=Nearly%20New&onesearchad=New&price-to=9000&year-from=2012&body-type=Hatchback&transmission=Automatic&exclude-writeoff-categories=on` + +### 联合国 + + diff --git a/docs/en/README.md b/docs/en/README.md index 5fb4c22be..f42acdca3 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -385,3 +385,7 @@ Provides a better reading experience (full text articles) over the official one. 1. Copy everything in the URL after `?`, for example: `https://www.autotrader.co.uk/car-search?radius=50&postcode=sw1a1aa&onesearchad=Used&onesearchad=Nearly%20New&onesearchad=New&price-to=9000&year-from=2012&body-type=Hatchback&transmission=Automatic&exclude-writeoff-categories=on` will produce `radius=50&postcode=sw1a1aa&onesearchad=Used&onesearchad=Nearly%20New&onesearchad=New&price-to=9000&year-from=2012&body-type=Hatchback&transmission=Automatic&exclude-writeoff-categories=on` + +### United Nations + + diff --git a/router.js b/router.js index cfa040c4d..e9536307c 100644 --- a/router.js +++ b/router.js @@ -411,9 +411,12 @@ router.get('/dongqiudi/result/:team', require('./routes/dongqiudi/result')); router.get('/dongqiudi/team_news/:team', require('./routes/dongqiudi/team_news')); router.get('/dongqiudi/player_news/:id', require('./routes/dongqiudi/player_news')); -// 维基百科 +// 维基百科 Wikipedia router.get('/wikipedia/mainland', require('./routes/wikipedia/mainland')); +// 联合国 United Nations +router.get('/un/scveto', require('./routes/un/scveto')); + // 雪球 router.get('/xueqiu/user/:id/:type?', require('./routes/xueqiu/user')); router.get('/xueqiu/favorite/:id', require('./routes/xueqiu/favorite')); diff --git a/routes/wikipedia/mainland.js b/routes/wikipedia/mainland.js index 279ce6b2a..d9a1472a5 100644 --- a/routes/wikipedia/mainland.js +++ b/routes/wikipedia/mainland.js @@ -1,5 +1,6 @@ const axios = require('../../utils/axios'); const cheerio = require('cheerio'); +const utils = require('./utils'); module.exports = async (ctx) => { const url = 'https://zh.wikipedia.org/wiki/Portal:%E4%B8%AD%E5%9C%8B%E5%A4%A7%E9%99%B8%E6%96%B0%E8%81%9E%E5%8B%95%E6%85%8B'; @@ -20,10 +21,7 @@ module.exports = async (ctx) => { for (let i = 0; i < list.length - 1; i++) { const item = { title: $(list[i]).text(), - desc: full - .find(`ul:nth-of-type(${i + 1})`) - .html() - .replace(/href="\/wiki/g, 'href="https://zh.wikipedia.org/wiki'), + desc: utils.ProcessLink(full.find(`ul:nth-of-type(${i + 1})`), 'zh'), url, }; items.push(item); diff --git a/routes/wikipedia/utils.js b/routes/wikipedia/utils.js new file mode 100644 index 000000000..3e110d8de --- /dev/null +++ b/routes/wikipedia/utils.js @@ -0,0 +1,23 @@ +const ProcessLink = ($, lang) => { + lang = !lang ? 'en' : lang; + + $.find('a').each((i, e) => { + if (e.attribs.href.startsWith('/wiki/')) { + e.attribs.href = `https://${lang}.wikipedia.org${e.attribs.href}`; + } + }); + + // img links + $.find('img').each((i, e) => { + if (e.attribs.src.startsWith('//upload.wikimedia.org/')) { + e.attribs.src = `https:${e.attribs.src}`; + e.attribs.srcset = ''; + } + }); + + return $.html(); +}; + +module.exports = { + ProcessLink, +}; diff --git a/un/scveto.js b/un/scveto.js new file mode 100644 index 000000000..b51352471 --- /dev/null +++ b/un/scveto.js @@ -0,0 +1,54 @@ +const axios = require('../utils/axios'); +const cheerio = require('cheerio'); +const utils = require('../routes/wikipedia/utils'); + +module.exports = async (ctx) => { + const url = 'https://en.wikipedia.org/wiki/List_of_vetoed_United_Nations_Security_Council_resolutions'; + + const response = await axios({ + method: 'get', + url, + }); + + const $ = cheerio.load(response.data); + const list = $('.sortable > tbody > tr').slice(1, 11); + + list.map((i) => utils.ProcessLink($(list[i]), 'en')); + + const items = []; + + for (let i = 0; i < list.length - 1; i++) { + const content = cheerio.load(list[i]); + + const date = content('td:nth-child(1)'); + const resolution = content('td:nth-child(2)'); + const meeting = content('td:nth-child(3)'); + const agenda = content('td:nth-child(4)'); + let country = content('td:nth-child(5)'); + country = cheerio.load(country.html().replace('
', ' and')); + + const item = { + title: `${country.text().trim()} vetoed a Resolution`, + desc: `${country('body').html()} vetoed ${agenda.html()}.

Resolution: ${resolution.html()}

Meeting Record: ${meeting.html()}`, + url: resolution.find('a').attr('href'), + guid: `scveto:${resolution.text()}`, + pubDate: new Date(date.text()).toISOString(), + }; + + items.push(item); + } + + ctx.state.data = { + title: 'United Nations Security Council Vetoed Resolutions', + link: 'http://research.un.org/en/docs/sc/quick/veto', + description: + 'The United Nations Security Council "veto power" refers to the power of the permanent members of the UN Security Council (China, France, Russia, United Kingdom, and United States) to veto any "substantive" resolution. Aka, abuse of power.', + item: items.map((item) => ({ + title: item.title, + description: item.desc, + link: item.url, + guid: item.guid, + pubDate: item.pubDate, + })), + }; +};