From c95762af473566ebf6df6c0b71e360e8a32b220f Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 23 Jan 2022 02:17:58 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=A2=85=E6=96=AF?= =?UTF-8?q?=E5=8C=BB=E5=AD=A6MedSci=20(#8736)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 50 ++++++++++++++++++++++++- lib/routes/medsci/recommend.js | 51 -------------------------- lib/v2/medsci/index.js | 67 ++++++++++++++++++++++++++++++++++ lib/v2/medsci/maintainer.js | 3 ++ lib/v2/medsci/radar.js | 13 +++++++ lib/v2/medsci/router.js | 3 ++ 6 files changed, 134 insertions(+), 53 deletions(-) delete mode 100644 lib/routes/medsci/recommend.js create mode 100644 lib/v2/medsci/index.js create mode 100644 lib/v2/medsci/maintainer.js create mode 100644 lib/v2/medsci/radar.js create mode 100644 lib/v2/medsci/router.js diff --git a/docs/new-media.md b/docs/new-media.md index 7de05d17a..81f597ea9 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2212,9 +2212,55 @@ column 为 third 时可选的 category: ## 梅斯医学 MedSci -### 推荐 +### 资讯 - + + +::: tip 提示 + +下表为科室对应的 sid,若想获得 tid,可以到对应科室页面 URL 中寻找 `t_id` 字段的值,下面是一个例子: + +如 [肿瘤 - NSCLC](https://www.medsci.cn/department/details?s_id=5&t_id=277) 的 URL 为 ,可以看到此时 `s_id` 对应 `sid` 的值为 5, `t_id` 对应 `tid` 的值为 277,所以可以得到路由 [`/medsci/5/277`](https://rsshub.app/medsci/5/277) + +::: + +| 心血管 | 内分泌 | 消化 | 呼吸 | 神经科 | +| ------ | ------ | ---- | ---- | ------ | +| 2 | 6 | 4 | 12 | 17 | + +| 传染科 | 精神心理 | 肾内科 | 风湿免疫 | 血液科 | +| ------ | -------- | ------ | -------- | ------ | +| 9 | 13 | 14 | 15 | 21 | + +| 老年医学 | 胃肠外科 | 血管外科 | 肝胆胰外 | 骨科 | +| -------- | -------- | -------- | -------- | ---- | +| 19 | 76 | 92 | 91 | 10 | + +| 普通外科 | 胸心外科 | 神经外科 | 泌尿外科 | 烧伤科 | +| -------- | -------- | -------- | -------- | ------ | +| 23 | 24 | 25 | 26 | 27 | + +| 整形科 | 麻醉疼痛 | 罕见病 | 康复医学 | 药械 | +| ------ | -------- | ------ | -------- | ---- | +| 28 | 29 | 304 | 95 | 11 | + +| 儿科 | 耳鼻咽喉 | 口腔科 | 眼科 | 政策人文 | +| ---- | -------- | ------ | ---- | -------- | +| 18 | 30 | 31 | 32 | 33 | + +| 营养全科 | 预防公卫 | 妇产科 | 中医科 | 急重症 | +| -------- | -------- | ------ | ------ | ------ | +| 34 | 35 | 36 | 37 | 38 | + +| 皮肤性病 | 影像放射 | 转化医学 | 检验病理 | 护理 | +| -------- | -------- | -------- | -------- | ---- | +| 39 | 40 | 42 | 69 | 79 | + +| 糖尿病 | 冠心病 | 肝病 | 乳腺癌 | +| ------ | ------ | ---- | ------ | +| 8 | 43 | 22 | 89 | + + ## 美国半导体行业协会 diff --git a/lib/routes/medsci/recommend.js b/lib/routes/medsci/recommend.js deleted file mode 100644 index 22a0fe1a7..000000000 --- a/lib/routes/medsci/recommend.js +++ /dev/null @@ -1,51 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const date = require('@/utils/date'); - -module.exports = async (ctx) => { - const currentUrl = 'http://www.medsci.cn'; - const response = await got({ - method: 'get', - url: currentUrl, - }); - - const $ = cheerio.load(response.data); - const list = $('div.composs-panel-inner div.composs-blog-list div.item div.item-content h2 a.ms-link') - .slice(0, 10) - .map((_, item) => { - item = $(item); - return { - title: item.text(), - link: item.attr('href'), - pubDate: date(item.parent().parent().find('span.item-meta-item').eq(0).text()), - }; - }) - .get(); - - const items = await Promise.all( - list.map((item) => - ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - - const content = cheerio.load(detailResponse.data); - const publishedTime = detailResponse.data.match(/"publishedTime":"(.*?)","publishedTimeString"/); - - const type = item.link.split('/')[3]; - - item.pubDate = publishedTime ? new Date(publishedTime[1]).toUTCString() : item.pubDate; - item.description = type === 'article' ? content('div.article-content-box').html() : content('shortcode-content').html(); - - return item; - }) - ) - ); - - ctx.state.data = { - title: '梅斯医学 - 推荐', - link: currentUrl, - item: items, - }; -}; diff --git a/lib/v2/medsci/index.js b/lib/v2/medsci/index.js new file mode 100644 index 000000000..d4e57a892 --- /dev/null +++ b/lib/v2/medsci/index.js @@ -0,0 +1,67 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate, parseRelativeDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + let sid = ctx.params.sid ?? ''; + const tid = ctx.params.tid ?? ''; + + sid = sid === 'recommend' ? '' : sid; + + const rootUrl = 'https://www.medsci.cn'; + const currentUrl = `${rootUrl}${sid ? `/department/details?s_id=${sid}&module=article${tid ? `&t_id=${tid}` : ''}` : ''}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('#articleList') + .find('.ms-link') + .toArray() + .map((item) => { + item = $(item); + + const pubDate = item.parent().parent().find('.item-meta-item').first().text(); + + return { + title: item.text(), + link: `${rootUrl}${item.attr('href').replace(/;jsessionid=[A-Z0-9]+/, '')}`, + pubDate: pubDate.indexOf('-') > 0 ? parseDate(pubDate) : parseRelativeDate(pubDate), + }; + }); + + 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); + + const pubDateMatches = detailResponse.data.match(/"publishedTime":"(.*)","publishedTimeString"/); + + item.author = content('.name').text(); + item.description = content('#content').html(); + item.pubDate = pubDateMatches ? parseDate(pubDateMatches[1]) : item.pubDate; + item.category = + content('meta[name="keywords"]') + .attr('content') + ?.split(/,|,/) + .filter((c) => c !== '' && c !== 'undefined') ?? []; + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${sid ? $('.department-header-active').text() : '推荐'} -${tid ? ` ${$('.department-keywords-ul .active').text()} -` : ''} MedSci.cn`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/medsci/maintainer.js b/lib/v2/medsci/maintainer.js new file mode 100644 index 000000000..379eb3518 --- /dev/null +++ b/lib/v2/medsci/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:sid?/:tid?': ['nczitzk'], +}; diff --git a/lib/v2/medsci/radar.js b/lib/v2/medsci/radar.js new file mode 100644 index 000000000..53e964446 --- /dev/null +++ b/lib/v2/medsci/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'medsci.cn': { + _name: '梅斯医学', + '.': [ + { + title: '资讯', + docs: 'https://docs.rsshub.app/new-media.html#mei-si-yi-xue-zi-xun', + source: ['/department/details', '/'], + target: (params) => `/medsci${params.s_id ? `/${params.s_id}${params.t_id ? `/${params.s_id}` : ''}` : ''}`, + }, + ], + }, +}; diff --git a/lib/v2/medsci/router.js b/lib/v2/medsci/router.js new file mode 100644 index 000000000..de33aa902 --- /dev/null +++ b/lib/v2/medsci/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:sid?/:tid?', require('./index')); +};