Skip to content

Commit

Permalink
feat(route): 增加大数据专家委员会和中国人工智能学会新闻 (#11510)
Browse files Browse the repository at this point in the history
* 增加大数据专家委员会和中国人工智能学会新闻

* 修复问题

* 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

---------
  • Loading branch information
tudou027 authored Feb 27, 2023
1 parent 9572f59 commit 65eaa2a
Show file tree
Hide file tree
Showing 21 changed files with 252 additions and 72 deletions.
12 changes: 0 additions & 12 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>

## 中国科学院青年创新促进会

### 最新博文
Expand Down
44 changes: 32 additions & 12 deletions docs/study.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>

## 金山词霸

### 每日一句
Expand Down Expand Up @@ -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"/>

## 中国人事考试网

### 通知公告
Expand Down
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
22 changes: 22 additions & 0 deletions lib/v2/caai/index.js
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions lib/v2/caai/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:caty': ['tudou027'],
};
13 changes: 13 additions & 0 deletions lib/v2/caai/radar.js
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions lib/v2/caai/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:caty', require('./index'));
};
1 change: 1 addition & 0 deletions lib/v2/caai/templates/description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{@ desc }}
46 changes: 46 additions & 0 deletions lib/v2/caai/utils.js
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 2 deletions lib/v2/ccfcv/index.js → lib/v2/ccf/ccfcv/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
});
}
Expand Down
5 changes: 5 additions & 0 deletions lib/v2/ccf/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
'/ccfcv/:channel/:category': ['elxy'],
'/news/:category?': ['nczitzk'],
'/tfbd/:caty/:id': ['tudou027'],
};
22 changes: 8 additions & 14 deletions lib/routes/ccf/news.js → lib/v2/ccf/news.js
Original file line number Diff line number Diff line change
@@ -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;
})
Expand Down
41 changes: 41 additions & 0 deletions lib/v2/ccf/radar.js
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions lib/v2/ccf/router.js
Original file line number Diff line number Diff line change
@@ -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'));
};
File renamed without changes.
1 change: 1 addition & 0 deletions lib/v2/ccf/templates/tfbd/description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{@ desc }}
22 changes: 22 additions & 0 deletions lib/v2/ccf/tfbd/index.js
Original file line number Diff line number Diff line change
@@ -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 changes: 47 additions & 0 deletions lib/v2/ccf/tfbd/utils.js
Original file line number Diff line number Diff line change
@@ -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 changes: 0 additions & 3 deletions lib/v2/ccfcv/maintainer.js

This file was deleted.

Loading

0 comments on commit 65eaa2a

Please sign in to comment.