Skip to content

Commit

Permalink
feat(route): 西南交通大学教务网、扬华素质网 (DIYgod#12101)
Browse files Browse the repository at this point in the history
* feat(route): 西南交通大学教务网、扬华素质网

* fix(route): fix wrong radar rule

* docs: fix format

* fix(route): format code style
  • Loading branch information
mobyw authored Mar 14, 2023
1 parent 22829d4 commit b4f9976
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/university.md
Original file line number Diff line number Diff line change
Expand Up @@ -3045,6 +3045,23 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS

## 西南交通大学

### 教务网

<Route author="mobyw" example="/swjtu/jwc" path="/swjtu/jwc"/>


### 扬华素质网

<Route author="mobyw" example="/swjtu/xg/tzgg" path="/swjtu/xg/:code?" :paramsDesc="['栏目(默认为tzgg)']">

栏目列表:

| 通知公告 | 扬华新闻 | 多彩学院 | 学工之家 |
| ---- | ---- | ---- | ---- |
| tzgg | yhxw | dcxy | xgzj |

</Route>

### 就业招聘信息

<Route author="qizidog" example="/swjtu/jyzpxx" path="/swjtu/jyzpxx"/>
Expand Down
67 changes: 67 additions & 0 deletions lib/v2/swjtu/jwc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');

const rootURL = 'http://jwc.swjtu.edu.cn';
const pageURL = `${rootURL}/vatuu/WebAction?setAction=newsList`;

const getItem = (item, cache) => {
const newsInfo = item.find('h3').find('a');
const newsTime = item.find('p').find('span').text().slice(0, 19);
const newsTitle = newsInfo.text();
const link = `${rootURL}${newsInfo.attr('href').slice(2)}`;
return cache.tryGet(link, async () => {
try {
const resp = await got({
method: 'get',
url: link,
});
const $$ = cheerio.load(resp.data);
let newsText = $$('.content-main').html();
if (!newsText) {
newsText = '转发通知';
}
return {
title: newsTitle,
pubDate: parseDate(String(newsTime)),
link,
description: newsText,
};
} catch (error) {
if (error.response && error.response.status === 404) {
return {
title: newsTitle,
pubDate: parseDate(String(newsTime)),
link,
description: '',
};
} else {
throw error;
}
}
});
};

module.exports = async (ctx) => {
const resp = await got({
method: 'get',
url: pageURL,
});

const $ = cheerio.load(resp.data);
const list = $("[class='littleResultDiv']");

const items = await Promise.all(
list.toArray().map((i) => {
const item = $(i);
return getItem(item, ctx.cache);
})
);

ctx.state.data = {
title: '西南交大-教务网通知',
link: pageURL,
item: items,
allowEmpty: true,
};
};
2 changes: 2 additions & 0 deletions lib/v2/swjtu/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
'/jtys/yjs': ['qizidog'],
'/jyzpxx': ['qizidog'],
'/jwc': ['mobyw'],
'/xg/:code?': ['mobyw'],
};
16 changes: 16 additions & 0 deletions lib/v2/swjtu/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,21 @@ module.exports = {
target: '/swjtu/jyzpxx',
},
],
jwc: [
{
title: '教务处通知',
docs: 'https://docs.rsshub.app/university.html#xi-nan-jiao-tong-da-xue',
source: ['/vatuu/WebAction', '/'],
target: '/swjtu/jwc',
},
],
xg: [
{
title: '扬华素质网',
docs: 'https://docs.rsshub.app/university.html#xi-nan-jiao-tong-da-xue',
source: ['/web/Home/PushNewsList', '/web/Home/NewsList', '/web/Home/ColourfulCollegeNewsList', '/web/Publicity/List', '/'],
target: '/swjtu/xg',
},
],
},
};
2 changes: 2 additions & 0 deletions lib/v2/swjtu/router.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = function (router) {
router.get('/jtys/yjs', require('./jtys/yjs'));
router.get('/jyzpxx', require('./jyzpxx'));
router.get('/jwc', require('./jwc'));
router.get('/xg/:code?', require('./xg'));
};
79 changes: 79 additions & 0 deletions lib/v2/swjtu/xg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');

const rootURL = 'http://xg.swjtu.edu.cn';
const listURL = {
tzgg: `${rootURL}/web/Home/PushNewsList?Lmk7LJw34Jmu=010j.shtml`,
yhxw: `${rootURL}/web/Home/NewsList?LJw34Jmu=011e.shtml`,
dcxy: `${rootURL}/web/Home/ColourfulCollegeNewsList`,
xgzj: `${rootURL}/web/Home/NewsList?xvw34vmu=010e.shtml`,
};

const getItem = (item, cache) => {
const newsInfo = item.find('h4').find('a');
const newsTime = item.find('span.ctxlist-time').text();
const newsTitle = newsInfo.text();
const link = `${rootURL}${newsInfo.attr('href')}`;
return cache.tryGet(link, async () => {
try {
const resp = await got({
method: 'get',
url: link,
});
const $$ = cheerio.load(resp.data);
let newsText = $$('.detail-content-text').html();
if (!newsText) {
newsText = '转发通知';
}
return {
title: newsTitle,
pubDate: parseDate(String(newsTime)),
link,
description: newsText,
};
} catch (error) {
if (error.response && error.response.status === 404) {
return {
title: newsTitle,
pubDate: parseDate(String(newsTime)),
link,
description: '',
};
} else {
throw error;
}
}
});
};

module.exports = async (ctx) => {
const code = ctx.params.code ?? 'tzgg';
const pageURL = listURL[code];

if (!pageURL) {
throw new Error('code not supported');
}

const resp = await got({
method: 'get',
url: pageURL,
});

const $ = cheerio.load(resp.data);
const list = $('div.right-side ul.block-ctxlist li');

const items = await Promise.all(
list.toArray().map((i) => {
const item = $(i);
return getItem(item, ctx.cache);
})
);

ctx.state.data = {
title: '西南交大-扬华素质网',
link: pageURL,
item: items,
allowEmpty: true,
};
};

0 comments on commit b4f9976

Please sign in to comment.