fix(route): 国家自然科学基金委基金要闻 (#10137)

* fix(route): 国家自然科学基金委基金要闻

* fix: add images
This commit is contained in:
Ethan Shen 2022-07-05 22:15:30 +08:00 committed by GitHub
parent 31f84a9706
commit 5deba293c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 161 additions and 176 deletions

View File

@ -265,6 +265,18 @@ pageClass: routes
</Route>
## 国家自然科学基金委员会
### 基金要闻
<Route author="Derekmini nczitzk" example="/gov/nsfc/news/jjyw" path="/gov/nsfc/news/:type?" :paramsDesc="['分类,默认为基金要闻,即 `jjyw`']" radar="1" rssbud="1">
| 基金要闻 | 通知公告 | 资助成果 | 科普快讯 |
| ---- | ---- | ---- | ---- |
| jjyw | tzgg | zzcg | kpkx |
</Route>
## 哈尔滨市科技局
### 政务公开

View File

@ -461,18 +461,6 @@ type 为 all 时category 参数不支持 cost 和 free
</Route>
## 国家自然科学基金委员会
### 新闻通知
<Route author="Derekmini" example="/nsfc/news/jjyw" path="/nsfc/news/:type?" :paramsDesc="['分类, 默认为 `jjyw`']" radar="1" rssbud="1">
| 基金要闻 | 通知公告 | 资助成果 | 科普快讯 |
| ---- | ---- | ---- | ---- |
| jjyw | tzgg | zzcg | kpkx |
</Route>
## 好队友
### 工作机会

View File

@ -1089,35 +1089,35 @@ module.exports = {
},
],
},
'nsfc.gov.cn': {
_name: '国家自然科学基金委员会',
www: [
{
title: '基金要闻',
docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
source: '/*',
target: '/nsfc/news/jjyw',
},
{
title: '通知公告',
docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
source: '/*',
target: '/nsfc/news/tzgg',
},
{
title: '资助成果',
docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
source: '/*',
target: '/nsfc/news/zzcg',
},
{
title: '科普快讯',
docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
source: '/*',
target: '/nsfc/news/kpkx',
},
],
},
// 'nsfc.gov.cn': {
// _name: '国家自然科学基金委员会',
// www: [
// {
// title: '基金要闻',
// docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
// source: '/*',
// target: '/nsfc/news/jjyw',
// },
// {
// title: '通知公告',
// docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
// source: '/*',
// target: '/nsfc/news/tzgg',
// },
// {
// title: '资助成果',
// docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
// source: '/*',
// target: '/nsfc/news/zzcg',
// },
// {
// title: '科普快讯',
// docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
// source: '/*',
// target: '/nsfc/news/kpkx',
// },
// ],
// },
'japanpost.jp': {
_name: '日本郵便',
'trackings.post': [

View File

@ -13,6 +13,7 @@ module.exports = {
'/moe/:type': ['Crawler995'],
'/nmpa/:path+': ['TonyRL'],
'/nrta/news/:category?': ['yuxinliu-alex'],
'/nsfc/news/:type?': ['Derekmini', 'nczitzk'],
'/pbc/goutongjiaoliu': ['nczitzk'],
'/pbc/gzlw': ['Fatpandac'],
'/pbc/tradeAnnouncement': ['nczitzk'],

83
lib/v2/gov/nsfc/index.js Normal file
View File

@ -0,0 +1,83 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const types = {
jjyw: {
title: '基金要闻',
url: '/publish/portal0/tab440/',
},
tzgg: {
title: '通知公告',
url: '/publish/portal0/tab442/',
},
zzcg: {
title: '资助成果',
url: '/publish/portal0/tab448/',
},
kpkx: {
title: '科普快讯',
url: '/publish/portal0/tab446/',
},
};
module.exports = async (ctx) => {
const type = ctx.params.type ?? 'jjyw';
const rootUrl = 'https://www.nsfc.gov.cn';
const currentUrl = `${rootUrl}${types[type].url}`;
const response = await got({
method: 'get',
url: currentUrl,
https: {
rejectUnauthorized: false,
},
});
const $ = cheerio.load(response.data);
let items = $('.fl a')
.toArray()
.map((item) => {
item = $(item);
const link = item.attr('href');
return {
title: item.attr('title'),
link: `${/^http/.test(link) ? '' : rootUrl}${link}`,
pubDate: parseDate(item.parent().next().text()),
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
if (/nsfc\.gov\.cn/.test(item.link)) {
const detailResponse = await got({
method: 'get',
url: item.link,
https: {
rejectUnauthorized: false,
},
});
const content = cheerio.load(detailResponse.data);
item.description = content('.content_xilan').html();
item.pubDate = timezone(parseDate(content('meta[name="docdate"]').attr('content')), +8);
}
return item;
})
)
);
ctx.state.data = {
title: `国家自然科学基金委员会 - ${$('title').text()}`,
link: currentUrl,
item: items,
};
};

View File

@ -450,6 +450,17 @@ module.exports = {
},
],
},
'nmpa.gov.cn': {
_name: '国家药品监督管理局',
'.': [
{
title: '通用',
docs: 'https://docs.rsshub.app/government.html#guo-jia-yao-pin-jian-du-guan-li-ju',
source: ['/*path'],
target: (params) => `/gov/nmpa/${params.path.replace('/index.html', '')}`,
},
],
},
'nrta.gov.cn': {
_name: '国家广播电视总局',
'.': [
@ -461,14 +472,32 @@ module.exports = {
},
],
},
'nmpa.gov.cn': {
_name: '国家药品监督管理局',
'nsfc.gov.cn': {
_name: '国家自然科学基金委员会',
'.': [
{
title: '通用',
docs: 'https://docs.rsshub.app/government.html#guo-jia-yao-pin-jian-du-guan-li-ju',
source: ['/*path'],
target: (params) => `/gov/nmpa/${params.path.replace('/index.html', '')}`,
title: '基金要闻',
docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui-ji-jin-yao-wen',
source: ['/*'],
target: '/nsfc/news/jjyw',
},
{
title: '通知公告',
docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui-ji-jin-yao-wen',
source: ['/*'],
target: '/nsfc/news/tzgg',
},
{
title: '资助成果',
docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui-ji-jin-yao-wen',
source: ['/*'],
target: '/nsfc/news/zzcg',
},
{
title: '科普快讯',
docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui-ji-jin-yao-wen',
source: ['/*'],
target: '/nsfc/news/kpkx',
},
],
},

View File

@ -13,6 +13,7 @@ module.exports = function (router) {
router.get('/moe/:type', require('./moe/moe'));
router.get(/\/nmpa\/([\w][\w/]+)?/, require('./nmpa/generic'));
router.get('/nrta/news/:category?', require('./nrta/news'));
router.get('/nsfc/news/:type?', require('./nsfc'));
router.get('/pbc/goutongjiaoliu', require('./pbc/goutongjiaoliu'));
router.get('/pbc/gzlw', require('./pbc/gzlw'));
router.get('/pbc/tradeAnnouncement', require('./pbc/tradeAnnouncement'));

View File

@ -1,3 +0,0 @@
module.exports = {
'/news/:type?': ['Derekmini'],
};

View File

@ -1,92 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');
const baseUrl = 'http://www.nsfc.gov.cn';
const typeMap = {
jjyw: {
name: '基金要闻',
url: '/publish/portal0/tab440/',
},
tzgg: {
name: '通知公告',
url: '/publish/portal0/tab442/',
},
zzcg: {
name: '资助成果',
url: '/publish/portal0/tab448/',
},
kpkx: {
name: '科普快讯',
url: '/publish/portal0/tab446/',
},
};
module.exports = async (ctx) => {
const type = ctx.params.type || 'jjyw';
const link = baseUrl + typeMap[type].url;
const response = await got({
method: 'get',
url: link,
headers: {
Referer: baseUrl,
},
});
const $ = cheerio.load(response.data);
const urlList = $('.contentnews .clearfix')
.slice(0, 10)
.map((i, e) => $('a', e).attr('href'))
.get();
const titleList = $('.contentnews .clearfix')
.slice(0, 10)
.map((i, e) => $('a', e).attr('title'))
.get();
const dateList = $('.contentnews .clearfix')
.slice(0, 10)
.map((i, e) => $('.fr', e).text())
.get();
const out = await Promise.all(
urlList.map(async (itemUrl, index) => {
itemUrl = url.resolve(baseUrl, itemUrl);
if (itemUrl.indexOf('.htm') !== -1) {
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await got.get(itemUrl);
const $ = cheerio.load(response.data);
const single = {
title: titleList[index],
link: itemUrl,
description: $('.content_xilan')
.html()
.replace(/src="\//g, `src="${url.resolve(baseUrl, '.')}`)
.replace(/href="\//g, `href="${url.resolve(baseUrl, '.')}`)
.trim(),
pubDate: dateList[index],
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
} else {
const single = {
title: titleList[index],
link: itemUrl,
description: '此链接为文件,请点击下载',
pubDate: dateList[index],
};
return Promise.resolve(single);
}
})
);
ctx.state.data = {
title: '国家自然科学基金委员会-' + typeMap[type].name,
link,
item: out,
};
};

View File

@ -1,31 +0,0 @@
module.exports = {
'nsfc.gov.cn': {
_name: '国自然基金委',
www: [
{
title: '基金要闻',
docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
source: '/*',
target: '/nsfc/news/jjyw',
},
{
title: '通知公告',
docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
source: '/*',
target: '/nsfc/news/tzgg',
},
{
title: '资助成果',
docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
source: '/*',
target: '/nsfc/news/zzcg',
},
{
title: '科普快讯',
docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
source: '/*',
target: '/nsfc/news/kpkx',
},
],
},
};

View File

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