From 54722cdca09e50825289ff4578557cddbb7d7120 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 8 Nov 2020 09:34:04 +0800 Subject: [PATCH] feat: add The Argument Audio from the Supreme Court of the United States (#6127) Co-authored-by: Henry Wang --- docs/en/government.md | 6 ++ docs/government.md | 6 ++ lib/router.js | 3 + lib/routes/us/supremecourt/argument_audio.js | 59 ++++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 lib/routes/us/supremecourt/argument_audio.js diff --git a/docs/en/government.md b/docs/en/government.md index e2e37f9485..832b21522c 100644 --- a/docs/en/government.md +++ b/docs/en/government.md @@ -10,6 +10,12 @@ pageClass: routes +## Supreme Court of the United States + +### Arguments Audios + + + ## United Nations ### Security Council Vetoed a Resolution diff --git a/docs/government.md b/docs/government.md index b5f6468956..6c1ee9600b 100644 --- a/docs/government.md +++ b/docs/government.md @@ -77,6 +77,12 @@ pageClass: routes +## 美国联邦最高法院 + +### 辩论音频 + + + ## 泉州市跨境电子商务协会 ### 新闻动态 diff --git a/lib/router.js b/lib/router.js index d36704c2ec..ba5df36b9f 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3472,6 +3472,9 @@ router.get('/grandchallenge/challenges', require('./routes/grandchallenge/challe // 西北工业大学 router.get('/nwpu/:column', require('./routes/nwpu/index')); +// 美国联邦最高法院 +router.get('/us/supremecourt/argument_audio/:year?', require('./routes/us/supremecourt/argument_audio')); + // 得到 router.get('/dedao/list/:caty?', require('./routes/dedao/list')); router.get('/dedao/:caty?', require('./routes/dedao/index')); diff --git a/lib/routes/us/supremecourt/argument_audio.js b/lib/routes/us/supremecourt/argument_audio.js new file mode 100644 index 0000000000..a7ef6ef54f --- /dev/null +++ b/lib/routes/us/supremecourt/argument_audio.js @@ -0,0 +1,59 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const year = ctx.params.year || new Date().getFullYear(); + + const rootUrl = 'https://www.supremecourt.gov'; + const imageUrl = `${rootUrl}/images/scous_seal.png`; + const currentUrl = `${rootUrl}/oral_arguments/argument_audio/${year}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.panel-body table tbody tr td span a') + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: `${rootUrl}/oral_arguments${item.attr('href').replace('..', '')}`, + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + content('#pagetitle').remove(); + + item.description = content('#pagemaindiv').html(); + item.title += ` : ${content('#ctl00_ctl00_MainEditable_mainContent_lblCaseName').text()}`; + item.pubDate = new Date(content('#ctl00_ctl00_MainEditable_mainContent_lblDate').text() + ' GMT-5').toUTCString(); + + item.itunes_item_image = imageUrl; + item.enclosure_url = content('audio source').attr('src'); + item.enclosure_type = 'audio/mpeg'; + + return item; + }) + ) + ); + + ctx.state.data = { + title: `Argument Audio ${year} - Supreme Court of the United States`, + link: currentUrl, + item: items, + itunes_author: 'Supreme Court of the United States', + image: imageUrl, + }; +};