From 6017666563e46b1c4e77b6b5aa197b6db094aa20 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Tue, 5 Jul 2022 22:33:37 +0800 Subject: [PATCH] feat(route): add U.S. Food and Drug Administration CDRHNew (#10139) * feat(route): add U.S. Food and Drug Administration CDRHNew * fix: pubDate * fix: pubDate --- docs/en/government.md | 6 ++++ docs/government.md | 6 ++++ lib/v2/fda/cdrh.js | 60 ++++++++++++++++++++++++++++++++++++++++ lib/v2/fda/maintainer.js | 3 ++ lib/v2/fda/radar.js | 13 +++++++++ lib/v2/fda/router.js | 3 ++ 6 files changed, 91 insertions(+) create mode 100644 lib/v2/fda/cdrh.js create mode 100644 lib/v2/fda/maintainer.js create mode 100644 lib/v2/fda/radar.js create mode 100644 lib/v2/fda/router.js diff --git a/docs/en/government.md b/docs/en/government.md index 33447cab7..f8022ac94 100644 --- a/docs/en/government.md +++ b/docs/en/government.md @@ -131,6 +131,12 @@ Category +## U.S. Food and Drug Administration + +### CDRHNew + + + ## United Nations ### Security Council Vetoed a Resolution diff --git a/docs/government.md b/docs/government.md index 0eb9250a9..f89f530ed 100644 --- a/docs/government.md +++ b/docs/government.md @@ -354,6 +354,12 @@ pageClass: routes +## 美国食品药品监督管理局 + +### CDRHNew + + + ## 美国中央情报局 ### 年度信息自由法报告 diff --git a/lib/v2/fda/cdrh.js b/lib/v2/fda/cdrh.js new file mode 100644 index 000000000..c236d0613 --- /dev/null +++ b/lib/v2/fda/cdrh.js @@ -0,0 +1,60 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.fda.gov'; + const currentUrl = `${rootUrl}/medical-devices/news-events-medical-devices/cdrhnew-news-and-updates`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('div[role="main"] a') + .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 30) + .toArray() + .map((item) => { + item = $(item); + + const link = item.attr('href'); + + return { + title: item.text(), + link: /^http/.test(link) ? link : `${rootUrl}${link}`, + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.author = content('meta[property="article:publisher"]').attr('content'); + + try { + item.pubDate = parseDate(content('meta[property="article:published_time"]').attr('content').split(', ').pop(), 'MM/DD/YYYY - HH:mm'); + } catch (e) { + item.pubDate = parseDate(content('meta[property="article:published_time"]').attr('content')); + } + + item.description = content('div[role="main"], .doc-content-area').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/fda/maintainer.js b/lib/v2/fda/maintainer.js new file mode 100644 index 000000000..2fbc261b0 --- /dev/null +++ b/lib/v2/fda/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/cdrh': ['nczitzk'], +}; diff --git a/lib/v2/fda/radar.js b/lib/v2/fda/radar.js new file mode 100644 index 000000000..a84167db3 --- /dev/null +++ b/lib/v2/fda/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'fda.gov': { + _name: 'U.S. Food and Drug Administration', + '.': [ + { + title: 'CDRHNew', + docs: 'https://docs.rsshub.app/government.html#mei-guo-shi-pin-yao-pin-jian-du-guan-li-ju-cdrhnew', + source: ['/medical-devices/news-events-medical-devices/cdrhnew-news-and-updates', '/'], + target: '/fda/cdrh', + }, + ], + }, +}; diff --git a/lib/v2/fda/router.js b/lib/v2/fda/router.js new file mode 100644 index 000000000..b0f07a5ff --- /dev/null +++ b/lib/v2/fda/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/cdrh', require('./cdrh')); +};