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
This commit is contained in:
Ethan Shen 2022-07-05 22:33:37 +08:00 committed by GitHub
parent 5deba293c1
commit 6017666563
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 91 additions and 0 deletions

View File

@ -131,6 +131,12 @@ Category
</RouteEn>
## U.S. Food and Drug Administration
### CDRHNew
<RouteEn author="nczitzk" example="/fda/cdrh" path="/fda/cdrh" />
## United Nations
### Security Council Vetoed a Resolution

View File

@ -354,6 +354,12 @@ pageClass: routes
</Route>
## 美国食品药品监督管理局
### CDRHNew
<Route author="nczitzk" example="/fda/cdrh" path="/fda/cdrh" />
## 美国中央情报局
### 年度信息自由法报告

60
lib/v2/fda/cdrh.js Normal file
View File

@ -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,
};
};

3
lib/v2/fda/maintainer.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
'/cdrh': ['nczitzk'],
};

13
lib/v2/fda/radar.js Normal file
View File

@ -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',
},
],
},
};

3
lib/v2/fda/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/cdrh', require('./cdrh'));
};