feat(route): add 上海市药品监督管理局 (#10138)

* feat(route): add 上海市药品监督管理局

* fix typo
This commit is contained in:
Ethan Shen 2022-07-05 21:34:03 +08:00 committed by GitHub
parent 1c8812b074
commit 31f84a9706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 1 deletions

View File

@ -388,6 +388,20 @@ pageClass: routes
<Route author="zcf0508" example="/gov/shanghai/wsjkw/yqtb" path="/gov/shanghai/wsjkw/yqtb"/>
### 上海市药品监督管理局
<Route author="nczitzk" example="/gov/shanghai/yjj/zh" path="/gov/shanghai/yjj/:path+" :paramsDesc="['路径参数']" radar="1" rssbud="1">
::: tip 提示
路径处填写对应页面 URL 中 `https://yjj.sh.gov.cn/``/index.html` 之间的字段,下面是一个例子。
若订阅 [最新信息公开 > 综合](https://yjj.sh.gov.cn/zh/index.html) 则将对应页面 URL <https://yjj.sh.gov.cn/zh/index.html>`https://yjj.sh.gov.cn/``/index.html` 之间的字段 `zh` 作为路径填入。此时路由为 [`/gov/shanghai/yjj/zh`](https://rsshub.app/gov/shanghai/yjj/zh)
:::
</Route>
## 世界贸易组织
### 争端解决新闻

View File

@ -26,6 +26,7 @@ module.exports = {
'/shenzhen/hrss/szksy/:caty/:page?': ['zlasd'],
'/shenzhen/zzb/:caty/:page?': ['zlasd'],
'/shanghai/rsj/ksxm': ['Fatpandac'],
'/shanghai/yjj/:path+': ['nczitzk'],
'/shanghai/wsjkw/yqtb': ['zcf0508'],
'/guangdong/tqyb/tfxtq': ['Fatpandac'],
'/guangdong/tqyb/sncsyjxh': ['Fatpandac'],

View File

@ -514,11 +514,19 @@ module.exports = {
rsj: [
{
title: '上海市职业能力考试院 考试项目',
docs: 'https://docs.rsshub.app/government.html#shang-hai-shi-zhi-ye-neng-li-kao-shi-yuan-kao-shi-xiang-mu',
docs: 'https://docs.rsshub.app/government.html#shang-hai-shi-ren-min-zheng-fu-shang-hai-shi-zhi-ye-neng-li-kao-shi-yuan-kao-shi-xiang-mu',
source: ['/'],
target: '/gov/shanghai/rsj/ksxm',
},
],
yjj: [
{
title: '上海市药品监督管理局',
docs: 'https://docs.rsshub.app/government.html#shang-hai-shi-ren-min-zheng-fu-shang-hai-shi-yao-pin-jian-du-guan-li-ju',
source: ['/'],
target: (params, url) => `/gov/shanghai/yjj/${new URL(url).match(/yjj\.sh\.gov\.cn\/(.*)\/index.html/)[1]}`,
},
],
},
'shaanxi.gov.cn': {
_name: '陕西省人民政府',

View File

@ -26,6 +26,7 @@ module.exports = function (router) {
router.get('/shenzhen/hrss/szksy/:caty/:page?', require('./shenzhen/hrss/szksy/index'));
router.get('/shenzhen/zzb/:caty/:page?', require('./shenzhen/zzb/index'));
router.get('/shanghai/rsj/ksxm', require('./shanghai/rsj/ksxm'));
router.get(/shanghai\/yjj\/([\w/-]+)?/, require('./shanghai/yjj'));
router.get('/shanghai/wsjkw/yqtb', require('./shanghai/wsjkw/yqtb'));
router.get('/guangdong/tqyb/tfxtq', require('./guangdong/tqyb/tfxtq'));
router.get('/guangdong/tqyb/sncsyjxh', require('./guangdong/tqyb/sncsyjxh'));

View File

@ -0,0 +1,54 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const params = ctx.path === '/shanghai/yjj' ? '/shanghai/yjj/zx-ylqx' : ctx.path;
const rootUrl = 'https://yjj.sh.gov.cn';
const currentUrl = `${rootUrl}${params.replace(/^\/shanghai\/yjj/, '')}/index.html`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
let items = $('.pageList li a')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: `${rootUrl}${item.attr('href')}`,
pubDate: parseDate(item.next().text()),
};
});
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.description = content('#ivs_content').html();
item.pubDate = timezone(parseDate(content('meta[name="pubdate"]').attr('content')), +8);
return item;
})
)
);
ctx.state.data = {
title: $('title').text().replace(/--/, ' - '),
link: currentUrl,
item: items,
};
};