feat(route): 增加大数据专家委员会和中国人工智能学会新闻 (#11510)

* 增加大数据专家委员会和中国人工智能学会新闻

* 修复问题

* fix: add docs for `caai`

fix: maintainer does not with match with router

* fix: add docs for `ccf/tfbd`

fix: use raw output for `art-template`

fix: standardise use of `got`
not using `got()` in one place and `got.get()` in another place

* refactor: migrate to v2

---------
This commit is contained in:
tudou027
2023-02-28 00:21:26 +08:00
committed by GitHub
parent 9572f59ce2
commit 65eaa2a6d9
21 changed files with 252 additions and 72 deletions
-12
View File
@@ -4509,18 +4509,6 @@ wechat-feeds 来源[已停止更新](https://github.com/hellodword/wechat-feeds/
</Route>
## 中国计算机学会
### 新闻
<Route author="nczitzk" example="/ccf/news" path="/ccf/news/:category?" :paramsDesc="['分类,见下表,默认为 CCF 新闻']">
| CCF 新闻 | CCF 聚焦 | ACM 信息 |
| ---------- | ------ | -------- |
| Media_list | Focus | ACM_News |
</Route>
## 中国科学院青年创新促进会
### 最新博文
+32 -12
View File
@@ -342,18 +342,6 @@ path="/ctfhub/upcoming/:limit?"
<Route author="xfangbao" example="/jijitang/article/latest" path="/jijitang/article/:id" :paramsDesc="['类别,latest 或者 recommand']"/>
## 计算机视觉专委
### 学术动态 - 分类
<Route author="elxy" example="/ccfcv/xsdt/xsqy" path="/ccfcv/:channel/:category" :paramsDesc="['频道,仅支持 `xsdt`', '分类,见下表,亦可在网站 url 里找到']">
| 学术前沿 | 热点征文 | 学术会议 |
| ---- | ---- | ---- |
| xsqy | rdzw | xshy |
</Route>
## 金山词霸
### 每日一句
@@ -659,12 +647,44 @@ path="/ctfhub/upcoming/:limit?"
<Route author="xyqfer" example="/icourse163/newest" path="/icourse163/newest" />
## 中国计算机学会
### 新闻
<Route author="nczitzk" example="/ccf/news" path="/ccf/news/:category?" :paramsDesc="['分类,见下表,默认为 CCF 新闻']">
| CCF 新闻 | CCF 聚焦 | ACM 信息 |
| ---------- | ------ | -------- |
| Media_list | Focus | ACM_News |
</Route>
### 计算机视觉专委会 - 学术动态 - 分类
<Route author="elxy" example="/ccf/ccfcv/xsdt/xsqy" path="/ccf/ccfcv/:channel/:category" :paramsDesc="['频道,仅支持 `xsdt`', '分类,见下表,亦可在网站 url 里找到']">
| 学术前沿 | 热点征文 | 学术会议 |
| ---- | ---- | ---- |
| xsqy | rdzw | xshy |
</Route>
### 大数据专家委员会
<Route author="tudou027" example="/ccf/tfbd/xwdt/tzgg" path="/ccf/tfbd/:caty/:id" :paramsDesc="['主分类,可在 URL 找到', '子分类,可在 URL 找到']" radar="1"/>
## 中国留学网
### 通知公告
<Route author="nczitzk" example="/cscse/tzgg" path="/cscse/tzgg"/>
## 中国人工智能学会
### 学会动态
<Route author="tudou027" example="/caai/45" path="/caai/:caty" :paramsDesc="['分类 ID,可在 URL 找到']" radar="1"/>
## 中国人事考试网
### 通知公告
+1 -1
View File
@@ -3541,7 +3541,7 @@ router.get('/vgn/:platform?', lazyloadRouteHandler('./routes/vgn/index'));
router.get('/iea/:category?', lazyloadRouteHandler('./routes/iea/index'));
// 中国计算机学会
router.get('/ccf/news/:category?', lazyloadRouteHandler('./routes/ccf/news'));
// router.get('/ccf/news/:category?', lazyloadRouteHandler('./routes/ccf/news'));
// The Brain
router.get('/thebrain/:category?', lazyloadRouteHandler('./routes/thebrain/blog'));
+22
View File
@@ -0,0 +1,22 @@
const utils = require('./utils');
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const base = utils.urlBase(ctx.params.caty);
const res = await got(base);
const info = utils.fetchAllArticles(res.data);
const $ = cheerio.load(res.data);
const details = await Promise.all(info.map((e) => utils.detailPage(e, ctx.cache)));
ctx.state.json = {
info,
};
ctx.state.data = {
title: '中国人工智能学会 - ' + $('.article-list h1').text(),
link: base,
item: details,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/:caty': ['tudou027'],
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'caai.cn': {
_name: '中国人工智能学会',
'.': [
{
title: '学会动态',
docs: 'https://docs.rsshub.app/study.html#zhong-guo-ren-gong-zhi-neng-xue-hui',
source: ['/index.php'],
target: (_, url) => `/caai/${url.match(/\/(\d+)\.html/)[1]}`,
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:caty', require('./index'));
};
+1
View File
@@ -0,0 +1 @@
{{@ desc }}
+46
View File
@@ -0,0 +1,46 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
const { art } = require('@/utils/render');
const path = require('path');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const base = 'http://www.caai.cn';
const urlBase = (caty) => base + `/index.php?s=/home/article/index/id/${caty}.html`;
const renderDesc = (desc) =>
art(path.join(__dirname, 'templates/description.art'), {
desc,
});
const detailPage = (e, cache) =>
cache.tryGet(e.link, async () => {
const result = await got(e.link);
const $ = cheerio.load(result.data);
e.description = $('div.article').html();
return e;
});
const fetchAllArticles = (data) => {
const $ = cheerio.load(data);
const articles = $('div.article-list > ul > li');
const info = articles.toArray().map((e) => {
const c = $(e);
const r = {
title: c.find('h3 a[href]').text().trim(),
link: base + c.find('h3 a[href]').attr('href'),
pubDate: timezone(parseDate(c.find('h4').text().trim(), 'YYYY-MM-DD'), +8),
};
return r;
});
return info;
};
module.exports = {
BASE: base,
urlBase,
fetchAllArticles,
detailPage,
renderDesc,
};
@@ -4,7 +4,7 @@ const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
const rootUrl = 'http://ccfcv.ccf.org.cn';
const rootUrl = 'https://tc.ccf.org.cn';
const cateTitleMap = {
xsdt: {
@@ -48,7 +48,7 @@ module.exports = async (ctx) => {
if (item.status !== 404) {
const content = cheerio.load(detailResponse.data);
const pdfUrl = content('div.g-box1 p a').attr('href');
item.description = art(path.join(__dirname, 'templates/description.art'), {
item.description = art(path.join(__dirname, '../templates/ccfcv/description.art'), {
pdfUrl,
});
}
+5
View File
@@ -0,0 +1,5 @@
module.exports = {
'/ccfcv/:channel/:category': ['elxy'],
'/news/:category?': ['nczitzk'],
'/tfbd/:caty/:id': ['tudou027'],
};
+8 -14
View File
@@ -1,42 +1,36 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const category = ctx.params.category || 'Media_list';
const rootUrl = 'https://www.ccf.org.cn';
const currentUrl = `${rootUrl}/${category}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const currentUrl = `${rootUrl}/${category}/`;
const response = await got(currentUrl);
const $ = cheerio.load(response.data);
const list = $('.tit a')
.slice(0, 10)
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: `${rootUrl}${item.attr('href')}`,
};
})
.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 detailResponse = await got(item.link);
const content = cheerio.load(detailResponse.data);
content('.new_info .num').remove();
item.description = content('.txt').html();
item.pubDate = new Date(content('.new_info span').text()).toUTCString();
item.pubDate = parseDate(content('.new_info span').text());
return item;
})
+41
View File
@@ -0,0 +1,41 @@
module.exports = {
'ccf.org.cn': {
_name: '中国计算机学会',
'.': [
{
title: '新闻',
docs: 'https://docs.rsshub.app/study.html#zhong-guo-ji-suan-ji-xue-hui',
source: ['/:category', '/'],
target: '/ccf/news/:category',
},
],
ccfcv: [
{
title: '计算机视觉专委会 - 学术动态 - 学术前沿',
docs: 'https://docs.rsshub.app/study.html#zhong-guo-ji-suan-ji-xue-hui',
source: ['/ccfcv/xsdt/xsqy/'],
target: '/ccf/ccfcv/xsdt/xsqy',
},
{
title: '计算机视觉专委会 - 学术动态 - 热点征文',
docs: 'https://docs.rsshub.app/study.html#zhong-guo-ji-suan-ji-xue-hui',
source: ['/ccfcv/xsdt/rdzw/'],
target: '/ccf/ccfcv/xsdt/rdzw',
},
{
title: '计算机视觉专委会 - 学术动态 - 学术会议',
docs: 'https://docs.rsshub.app/study.html#zhong-guo-ji-suan-ji-xue-hui',
source: ['/ccfcv/xsdt/xshy/'],
target: '/ccf/ccfcv/xsdt/xshy',
},
],
tfbd: [
{
title: '大数据专家委员会',
docs: 'https://docs.rsshub.app/study.html#zhong-guo-ji-suan-ji-xue-hui',
source: ['/tfbd/:caty/:id', '/'],
target: '/ccf/tfbd/:caty/:id',
},
],
},
};
+5
View File
@@ -0,0 +1,5 @@
module.exports = function (router) {
router.get('/ccfcv/:channel/:category', require('./ccfcv/index'));
router.get('/news/:category?', require('./news'));
router.get('/tfbd/:caty/:id', require('./tfbd/index'));
};
@@ -0,0 +1 @@
{{@ desc }}
+22
View File
@@ -0,0 +1,22 @@
const utils = require('./utils');
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const base = utils.urlBase(ctx.params.caty, ctx.params.id);
const res = await got(base);
const info = utils.fetchAllArticles(res.data);
const $ = cheerio.load(res.data);
const details = await Promise.all(info.map((e) => utils.detailPage(e, ctx.cache)));
ctx.state.json = {
info,
};
ctx.state.data = {
title: '大数据专家委员会 - ' + $('.position a:last-child').text(),
link: base,
item: details,
};
};
+47
View File
@@ -0,0 +1,47 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
const { art } = require('@/utils/render');
const path = require('path');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const base = 'http://tfbd.ccf.org.cn';
const urlBase = (caty, id) => base + `/tfbd/${caty}/${id}/`;
const renderDesc = (desc) =>
art(path.join(__dirname, '../templates/tfbd/description.art'), {
desc,
});
const detailPage = (e, cache) =>
cache.tryGet(e.link, async () => {
const result = await got(e.link);
const $ = cheerio.load(result.data);
e.description = $('div.articleCon').html();
return e;
});
const fetchAllArticles = (data) => {
const $ = cheerio.load(data);
const articles = $('div.file-list div.article-item');
const info = articles.toArray().map((e) => {
const c = $(e);
const r = {
title: c.find('h3 a[href]').text().trim(),
link: base + c.find('h3 a[href]').attr('href'),
pubDate: timezone(parseDate(c.find('p').text().trim(), 'YYYY-MM-DD'), +8),
};
return r;
});
return info;
};
module.exports = {
BASE: base,
urlBase,
fetchAllArticles,
detailPage,
renderDesc,
};
-3
View File
@@ -1,3 +0,0 @@
module.exports = {
'/:channel/:category': ['elxy'],
};
-25
View File
@@ -1,25 +0,0 @@
module.exports = {
'ccfcv.ccf.org.cn': {
_name: '计算机视觉专委会',
www: [
{
title: '学术动态 - 学术前沿',
docs: 'https://docs.rsshub.app/study.html#ji-suan-ji-shi-jue-zhuan-wei-hui',
source: ['/ccfcv/xsdt/xsqy/'],
target: '/ccfcv/xsdt/xsqy',
},
{
title: '学术动态 - 热点征文',
docs: 'https://docs.rsshub.app/study.html#ji-suan-ji-shi-jue-zhuan-wei-hui',
source: ['/ccfcv/xsdt/rdzw/'],
target: '/ccfcv/xsdt/rdzw',
},
{
title: '学术动态 - 学术会议',
docs: 'https://docs.rsshub.app/study.html#ji-suan-ji-shi-jue-zhuan-wei-hui',
source: ['/ccfcv/xsdt/xshy/'],
target: '/ccfcv/xsdt/xshy',
},
],
},
};
-3
View File
@@ -1,3 +0,0 @@
module.exports = function (router) {
router.get('/:channel/:category', require('./index'));
};