feat(route): `/sdu/wh/jwc/:column?` for 山东大学(威海)教务处 (#9585)

* feat: extractor for https://jwc.wh.sdu.edu.cn/

* feat(route): /sdu/wh/jwc for 山东大学(威海)教务处

* feat(radar): 山东大学(威海)教务处

* fix(radar): match wildcard path for 山东大学(威海)新闻网

* docs: for route /sdu/wh/jwc

* fix: update maintainer.js
This commit is contained in:
Levi Zim 2022-04-20 21:13:12 +08:00 committed by GitHub
parent fccb91838d
commit a43542ee2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 137 additions and 1 deletions

View File

@ -2021,6 +2021,16 @@ type 列表:
</Route>
### 教务处
<Route author="kxxt" example="/sdu/wh/jwc/gztz" path="/sdu/wh/jwc/:column?" :paramsDesc="['专栏名称,默认为工作通知(`gztz`']" radar="1" rssbud="1">
| 规章制度 | 专业建设 | 实践教学 | 支部风采 | 服务指南 | 教务要闻 | 工作通知 | 教务简报 | 常用下载 |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| gzzd | zyjs | sjjx | zbfc | fwzn | jwyw | gztz | jwjb | cyxz |
</Route>
## 上海大学
### 上海大学官网信息

View File

@ -3,7 +3,7 @@ module.exports = {
news: {
name: '山东大学(威海)新闻网',
route: '/news',
source: ['/'],
source: ['/*path', '/'],
titlePrefix: '(威海)新闻网|',
docs: 'https://docs.rsshub.app/university.html#shan-dong-da-xue-wei-hai',
getTarget(url) {
@ -57,5 +57,54 @@ module.exports = {
},
},
},
jwc: {
name: '山东大学(威海)教务处',
route: '/jwc',
source: ['/*path', '/'],
titlePrefix: '(威海)教务处|',
docs: 'https://docs.rsshub.app/university.html#shan-dong-da-xue-wei-hai',
getTarget(url) {
return this.route + '/' + url.replace(/\.htm$/, '');
},
url: 'https://jwc.wh.sdu.edu.cn/',
columns: {
gzzd: {
name: '规章制度',
url: 'gzzd.htm',
},
zyjs: {
name: '专业建设',
url: 'zyjs.htm',
},
sjjx: {
name: '实践教学',
url: 'sjjx.htm',
},
zbfc: {
name: '支部风采',
url: 'zbfc.htm',
},
fwzn: {
name: '服务指南',
url: 'fwzn.htm',
},
jwyw: {
name: '教务要闻',
url: 'jwyw.htm',
},
gztz: {
name: '工作通知',
url: 'gztz.htm',
},
jwjb: {
name: '教务简报',
url: 'jwjb.htm',
},
cyxz: {
name: '常用下载',
url: 'cyxz.htm',
},
},
},
},
};

View File

@ -8,5 +8,8 @@ module.exports = async (link, ctx) => {
if (link.startsWith('https://www.sdrj.sdu.edu.cn/')) {
return await require('./sdrj')(link, ctx);
}
if (link.startsWith('https://jwc.wh.sdu.edu.cn/')) {
return await require('./wh/jwc')(link, ctx);
}
return {};
};

View File

@ -0,0 +1,24 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (link, ctx) =>
await ctx.cache.tryGet(link, async () => {
let content, exactDate;
try {
const result = await got(link);
const $ = cheerio.load(result.data);
const form = $("form[name='_newscontent_fromname']");
form.find('h2').remove();
const exactDateElement = form.find('#author');
const exactDateStr = exactDateElement.text();
exactDateElement.remove();
content = form.html();
const exactDateText = exactDateStr.match(/^创建时间:(?<date>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})/).groups.date;
exactDate = timezone(parseDate(exactDateText, 'YYYY-MM-DD HH:mm:ss'), +8);
return { description: content, exactDate };
} catch (e) {
return { description: content, exactDate };
}
});

View File

@ -5,4 +5,5 @@ module.exports = {
'/mech/:type?': ['Ji4n1ng'],
'/sc/:type?': ['Ji4n1ng'],
'/wh/news/:column?': ['kxxt'],
'/wh/jwc/:column?': ['kxxt'],
};

View File

@ -9,6 +9,12 @@ module.exports = {
source: wh.news.source,
target: '/sdu/wh' + wh.news.getTarget(value.url),
})),
'jwc.wh': Object.entries(wh.jwc.columns).map(([, value]) => ({
title: wh.jwc.titlePrefix + value.name,
docs: wh.jwc.docs,
source: wh.jwc.source,
target: '/sdu/wh' + wh.jwc.getTarget(value.url),
})),
'www.cmse': [
{
title: '材料科学与工程学院通知',

View File

@ -5,4 +5,5 @@ module.exports = function (router) {
router.get('/mech/:type?', require('./mech'));
router.get('/sc/:type?', require('./sc'));
router.get('/wh/news/:column?', require('./wh/news'));
router.get('/wh/jwc/:column?', require('./wh/jwc'));
};

42
lib/v2/sdu/wh/jwc.js Normal file
View File

@ -0,0 +1,42 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const data = require('../data').wh.jwc;
const extractor = require('../extractor');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const column = ctx.params.column ?? 'gztz';
const baseUrl = data.url;
const response = await got(baseUrl + data.columns[column].url);
const $ = cheerio.load(response.data);
const items = $('.articleul li');
const out = await Promise.all(
items.map(async (index, item) => {
item = $(item);
const anchor = item.find('a');
const dateElement = item.find('div:last-of-type');
const dateText = dateElement.text();
dateElement.remove();
const href = anchor.attr('href');
const link = href.startsWith('http') ? href : baseUrl + href;
const title = item.text();
const { description, author: exactAuthor, exactDate } = await ctx.cache.tryGet(link, async () => await extractor(link, ctx));
const author = exactAuthor ?? '教务处';
const pubDate = exactDate ?? timezone(parseDate(dateText.slice(1, dateText.length - 1), 'YYYY-MM-DD'), +8);
return {
title,
link,
description,
pubDate,
author,
};
})
);
ctx.state.data = {
title: `${data.name} ${data.columns[column].name}`,
link: baseUrl + data.columns[column].url,
item: out,
};
};