Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add 生物探索 #7897

Merged
merged 3 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/en/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more

</RouteEn>

## biodiscover.com

### Channel

<Route author="aidistan" example="/biodiscover" path="/biodiscover/:channel?" :paramsDesc="['channel, see below, `home` by default']">

| Home | Research | Industry | Financing | Politics | Celebrity | Company | Product | Activity |
| ---- | -------- | -------- | --------- | -------- | --------- | ------- | ------- | -------- |
| home | research | industry | financing | politics | celebrity | company | product | activity |

</Route>

## BOF

### Home
Expand Down
12 changes: 12 additions & 0 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -1938,6 +1938,18 @@ column 为 third 时可选的 category:

<Route author="nczitzk" example="/bioon/latest" path="/bioon/latest"/>

## 生物探索

### 频道

<Route author="aidistan" example="/biodiscover" path="/biodiscover/:channel?" :paramsDesc="['频道,见下表,默认为首页']">

| 首页 | 研究 | 产业 | 融资 | 时政 | 人物 | 公司 | 新品 | 活动 |
| ---- | -------- | -------- | --------- | -------- | --------- | ------- | ------- | -------- |
| home | research | industry | financing | politics | celebrity | company | product | activity |

</Route>

## 世界卫生组织 WHO

### 媒体中心
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4154,4 +4154,7 @@ router.get('/tanchinese/:category?', require('./routes/tanchinese'));
// Harvard
router.get('/harvard/health/blog', require('./routes/universities/harvard/health/blog'));

// 生物探索
router.get('/biodiscover/:channel?', require('./routes/biodiscover'));

module.exports = router;
49 changes: 49 additions & 0 deletions lib/routes/biodiscover/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
const channel = ctx.params.channel || 'home';
const listUrl = 'http://www.biodiscover.com' + (channel === 'home' ? '/' : '/news/' + channel);
const response = await got({ url: listUrl });

const $ = cheerio.load(response.data);
const title = $('.list-title').text().replace(/\s/g, '');
const urls = $('.news_list li h2 a')
.map((_, item) => 'http://www.biodiscover.com' + $(item).attr('href'))
.toArray();

ctx.state.data = {
title: '生物探索' + (title ? ` - ${title}` : ''),
link: listUrl,
description: $('meta[name=description]').attr('content'),
allowEmpty: true,
item: await Promise.all(
urls.map(
async (url) =>
await ctx.cache.tryGet(url, async () => {
const detailResponse = await got({ url });
const $ = cheerio.load(detailResponse.data);

let date = $('.from').children().last().text();
const re = /(\d+)天前/.exec(date);
aidistan marked this conversation as resolved.
Show resolved Hide resolved
if (re) {
date = new Date(new Date() - re[1] * 1000 * 3600 * 24);
} else {
date = new Date(date);
}

return {
title: $('.article_title').text(),
category: $('.tag a')
.map((_, a) => $(a).text())
.toArray(),
description: $('.article').html(),
aidistan marked this conversation as resolved.
Show resolved Hide resolved
pubDate: timezone(date, +8),
link: url,
};
})
)
),
};
};