diff --git a/lib/routes/whitehouse/briefing-room.ts b/lib/routes/whitehouse/briefing-room.ts deleted file mode 100644 index ef2c241d94d42b..00000000000000 --- a/lib/routes/whitehouse/briefing-room.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { Route } from '@/types'; -import cache from '@/utils/cache'; -import got from '@/utils/got'; -import { load } from 'cheerio'; -import { parseDate } from '@/utils/parse-date'; - -export const route: Route = { - path: '/briefing-room/:category?', - categories: ['government'], - example: '/whitehouse/briefing-room', - parameters: { category: 'Category, see below, all by default' }, - features: { - requireConfig: false, - requirePuppeteer: false, - antiCrawler: false, - supportBT: false, - supportPodcast: false, - supportScihub: false, - }, - radar: [ - { - source: ['whitehouse.gov/briefing-room/:category', 'whitehouse.gov/'], - target: '/briefing-room/:category', - }, - ], - name: 'Briefing Room', - maintainers: ['nczitzk'], - handler, - description: `| All | Blog | Legislation | Presidential Actions | Press Briefings | Speeches and Remarks | Statements and Releases | - | --- | ---- | ----------- | -------------------- | --------------- | -------------------- | ----------------------- | - | | blog | legislation | presidential-actions | press-briefings | speeches-remarks | statements-releases |`, -}; - -async function handler(ctx) { - const category = ctx.req.param('category') ?? ''; - - const rootUrl = 'https://www.whitehouse.gov'; - const currentUrl = `${rootUrl}/briefing-room/${category}`; - const response = await got({ - method: 'get', - url: currentUrl, - }); - - const $ = load(response.data); - - const list = $('.news-item__title') - .slice(0, 10) - .map((_, item) => { - item = $(item); - return { - title: item.text(), - link: item.attr('href'), - }; - }) - .get(); - - const items = await Promise.all( - list.map((item) => - cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = load(detailResponse.data); - - item.description = content('.body-content').html(); - item.pubDate = parseDate(content('meta[property="article:published_time"]').attr('content')); - - return item; - }) - ) - ); - - return { - title: $('title').text(), - link: currentUrl, - item: items, - }; -} diff --git a/lib/routes/whitehouse/news.ts b/lib/routes/whitehouse/news.ts new file mode 100644 index 00000000000000..97b1690ba7fd70 --- /dev/null +++ b/lib/routes/whitehouse/news.ts @@ -0,0 +1,82 @@ +import { Route } from '@/types'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/news/:category?', + categories: ['government'], + example: '/whitehouse/news', + parameters: { category: 'Category, see below, all by default' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['whitehouse.gov/:category', 'whitehouse.gov/'], + target: '/news/:category', + }, + ], + name: 'News', + maintainers: ['nczitzk', 'hkamran80'], + handler, + description: `| All | Articles | Briefings and Statements | Presidential Actions | Remarks | + | --- | -------- | ------------------------ | -------------------- | ------- | + | | articles | briefings-statements | presidential-actions | remarks |`, +}; + +async function handler(ctx) { + const category = ctx.req.param('category') ?? 'news'; + + const rootUrl = 'https://www.whitehouse.gov'; + const currentUrl = `${rootUrl}/${category}/`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = load(response.data); + + const list = $('.post') + .toArray() + .map((item) => { + item = $(item); + + const a = item.find('a').first(); + return { + title: a.text(), + link: a.attr('href'), + pubDate: parseDate(item.find('time').attr('datetime')), + category: [item.find('a[rel^=tag]').first().text()], + }; + }); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const response = await got({ + method: 'get', + url: item.link, + }); + const $ = load(response.data); + + $('.wp-block-whitehouse-topper').remove(); + item.description = $('.entry-content').html(); + + return item; + }) + ) + ); + + return { + title: $('title').text(), + link: currentUrl, + item: items, + }; +} diff --git a/lib/routes/whitehouse/ostp.ts b/lib/routes/whitehouse/ostp.ts deleted file mode 100644 index fcf549f5216045..00000000000000 --- a/lib/routes/whitehouse/ostp.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { Route } from '@/types'; -import cache from '@/utils/cache'; -import got from '@/utils/got'; -import { load } from 'cheerio'; -import { parseDate } from '@/utils/parse-date'; - -export const route: Route = { - path: '/ostp', - categories: ['government'], - example: '/whitehouse/ostp', - parameters: {}, - features: { - requireConfig: false, - requirePuppeteer: false, - antiCrawler: false, - supportBT: false, - supportPodcast: false, - supportScihub: false, - }, - radar: [ - { - source: ['whitehouse.gov/ostp', 'whitehouse.gov/'], - }, - ], - name: 'Office of Science and Technology Policy', - maintainers: ['LyleLee'], - handler, - url: 'whitehouse.gov/ostp', -}; - -async function handler() { - const rootUrl = 'https://www.whitehouse.gov'; - const currentUrl = `${rootUrl}/ostp/news-updates`; - const response = await got({ - method: 'get', - url: currentUrl, - }); - - const $ = load(response.data); - - const list = $('.news-item__title') - .slice(0, 10) - .map((_, item) => { - item = $(item); - return { - title: item.text(), - link: item.attr('href'), - }; - }) - .get(); - - const items = await Promise.all( - list.map((item) => - cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = load(detailResponse.data); - - item.description = content('.body-content').html(); - item.pubDate = parseDate(content('time.published').attr('datetime')); - item.author = content('span.tax-links.cat-links > a').text(); - - return item; - }) - ) - ); - - return { - title: 'Whitehouse OSTP', - link: currentUrl, - description: 'Whitehouse Office of Science and Technology Policy', - item: items, - }; -}