Skip to content

Commit

Permalink
feat:update 工学新闻、水声工程学院通知 route (DIYgod#4581)
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek authored Apr 28, 2020
1 parent 96f21f5 commit 853f00e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 42 deletions.
17 changes: 7 additions & 10 deletions assets/radar-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -1410,30 +1410,27 @@
title: '水声学院 - 新闻动态',
docs: 'https://docs.rsshub.app/university.html#ha-er-bin-gong-cheng-da-xue',
source: '/*',
target: '/heu/shuisheng/xwdt',
target: '/heu/uae/xwdt',
},
{
title: '研究生院 - 通知公告',
docs: 'https://docs.rsshub.app/university.html#ha-er-bin-gong-cheng-da-xue',
source: '/*',
target: '/heu/shuisheng/tzgg',
target: '/heu/uae/tzgg',
},
],
},
'gongxue.cn': {
_name: '工学网',
'.': [
news: [
{
title: '要闻',
title: '工学新闻 - 要闻',
docs: 'https://docs.rsshub.app/university.html#ha-er-bin-gong-cheng-da-xue',
source: '/*',
target: '/heu/gongxue/yw',
target: '/heu/news/yw',
},
{
title: '时讯',
title: '工学新闻 - 时讯',
docs: 'https://docs.rsshub.app/university.html#ha-er-bin-gong-cheng-da-xue',
source: '/*',
target: '/heu/gongxue/sx',
target: '/heu/news/sx',
},
],
},
Expand Down
10 changes: 5 additions & 5 deletions docs/university.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ category 列表:

### 研究生院

<Route author="XYenon Derekmini" example="/heu/yjsy/announcement" path="/heu/yjsy/:type?" :paramsDesc="['分类, 默认为 `announcement`']" radar="1">
<Route author="XYenon Derekmini" example="/heu/yjsy/announcement" path="/heu/yjsy/:type?" :paramsDesc="['栏目, 默认为 `announcement`']" radar="1">

| 通知公告 | 新闻动态 | 国家公派项目 | 国际合作与交流项目 |
| ------------ | -------- | ------------ | ------------------ |
Expand All @@ -435,17 +435,17 @@ category 列表:

### 就业服务平台

<Route author="Derekmini" example="/heu/job/tzgg" path="/heu/job/:type?" :paramsDesc="['分类, 默认为 `tzgg`']" radar="1">
<Route author="Derekmini" example="/heu/job/tzgg" path="/heu/job/:type?" :paramsDesc="['栏目, 默认为 `tzgg`']" radar="1">

| 通知公告 |
| -------- |
| tzgg |

</Route>

### 工学网
### 工学新闻

<Route author="Derekmini XYenon" example="/heu/gongxue/yw" path="/heu/gongxue/:type?" :paramsDesc="['分类, 默认为 `yw`']" radar="1">
<Route author="Derekmini XYenon" example="/heu/news/yw" path="/heu/news/:type?" :paramsDesc="['栏目, 默认为 `yw`']" radar="1">

| 要闻 | 时讯 |
| ---- | ---- |
Expand All @@ -455,7 +455,7 @@ category 列表:

### 水声工程学院通知

<Route author="Derekmini" example="/heu/shuisheng/xwdt" path="/heu/shuisheng/:type?" :paramsDesc="['分类, 默认为 `xwdt`']" radar="1">
<Route author="Derekmini" example="/heu/uae/xwdt" path="/heu/uae/:type?" :paramsDesc="['栏目, 默认为 `xwdt`']" radar="1">

| 新闻动态 | 通知公告 |
| -------- | -------- |
Expand Down
6 changes: 4 additions & 2 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,10 @@ router.get('/nchu/jwc/:type?', require('./routes/universities/nchu/jwc'));
// 哈尔滨工程大学
router.get('/heu/ugs/news/:author?/:category?', require('./routes/universities/heu/ugs/news'));
router.get('/heu/yjsy/:type?', require('./routes/universities/heu/yjsy'));
router.get('/heu/gongxue/:type?', require('./routes/universities/heu/gongxue'));
router.get('/heu/shuisheng/:type?', require('./routes/universities/heu/shuisheng'));
router.get('/heu/gongxue/:type?', require('./routes/universities/heu/news'));
router.get('/heu/news/:type?', require('./routes/universities/heu/news'));
router.get('/heu/shuisheng/:type?', require('./routes/universities/heu/uae'));
router.get('/heu/uae/:type?', require('./routes/universities/heu/uae'));
router.get('/heu/job/:type?', require('./routes/universities/heu/job'));

// 重庆大学
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');
const iconv = require('iconv-lite');

const baseUrl = 'http://gongxue.cn';
const baseUrl = 'http://news.hrbeu.edu.cn';

const typeMap = {
yw: {
name: '要闻',
url: '/news/ShowClass.asp?ClassID=4383',
url: '/xw/yw.htm',
},
sx: {
name: '时讯',
url: '/news/ShowClass.asp?ClassID=4315',
url: '/xw/sx.htm',
},
};

Expand All @@ -25,55 +24,47 @@ module.exports = async (ctx) => {
headers: {
Referer: baseUrl,
},
responseType: 'buffer',
});
const responseHtml = iconv.decode(response.data, 'gbk');
const $ = cheerio.load(responseHtml);
const $ = cheerio.load(response.data);

const urlList = $('.wenzhangzhengwen tr:nth-child(-n+20)')
const urlList = $('.list-left-ul .txt-elise')
.slice(0, 10)
.map((i, e) => $('a', e).attr('href'))
.get();

const titleList = $('.wenzhangzhengwen tr:nth-child(-n+20)')
const titleList = $('.list-left-ul .txt-elise')
.slice(0, 10)
.map((i, e) => $('a', e).text())
.map((i, e) => $('a', e).attr('title'))
.get();

const dateList = $('.wenzhangzhengwen tr:nth-child(-n+20)')
const dateList = $('.list-left-ul .txt-elise')
.slice(0, 10)
.map((i, e) => $('td[align="right"]', e).text())
.map((i, e) => $('span', e).text())
.get();

const out = await Promise.all(
urlList.map(async (itemUrl, index) => {
const itemYear = itemUrl.substring(6, 10);
itemUrl = url.resolve(baseUrl, itemUrl);
if (itemUrl.indexOf('.html') !== -1) {
if (itemUrl.indexOf('.htm') !== -1) {
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await got({
method: 'get',
url: itemUrl,
responseType: 'buffer',
});
const responseHtmlItem = iconv.decode(response.data, 'gbk');
const $ = cheerio.load(responseHtmlItem);
const response = await got.get(itemUrl);
const $ = cheerio.load(response.data);
const single = {
title: titleList[index],
link: itemUrl,
description: $('.wenzhangzhengwen').html(),
pubDate: itemYear + '-' + dateList[index],
description: $('.v_news_content').html(),
pubDate: dateList[index],
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
} else {
const single = {
title: titleList[index],
link: itemUrl,
description: '此链接为文件,请点击下载',
description: '此链接为跳转,点击标题查看',
pubDate: dateList[index],
};
return Promise.resolve(single);
Expand All @@ -82,7 +73,7 @@ module.exports = async (ctx) => {
);

ctx.state.data = {
title: '工学网-' + typeMap[type].name,
title: '工学新闻-' + typeMap[type].name,
link: link,
item: out,
};
Expand Down
File renamed without changes.

0 comments on commit 853f00e

Please sign in to comment.