fix(route): 西南石油大学 办公网、教务处、计算机与软件学院、电气信息学院 (#15621)
* fix: 西南石油大学 办公网 * fix: 西南石油大学 计算机与软件学院、电气信息学院、教务处 * 西南石油大学 办公网:移除 学术报告(网页改版) * use `map()` * use `.html()!` instead of `.html()?.toString()`
This commit is contained in:
parent
34e1e75eba
commit
ea87eb8dbc
|
|
@ -1,4 +1,4 @@
|
|||
import { Route } from '@/types';
|
||||
import { DataItem, Route, Data } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import { joinUrl } from './utils';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
|
@ -29,13 +29,13 @@ export const route: Route = {
|
|||
maintainers: ['CYTMWIA'],
|
||||
handler,
|
||||
url: 'swpu.edu.cn/',
|
||||
description: `| 栏目 | 重要通知公告 | 部门通知公告 | 本周活动 | 学术报告 |
|
||||
| ---- | ------------ | ------------ | -------- | -------- |
|
||||
| 代码 | zytzgg | bmtzgg | bzhd | xsbg |`,
|
||||
description: `| 栏目 | 重要通知公告 | 部门通知公告 | 本周活动 |
|
||||
| ---- | ------------ | ------------ | -------- |
|
||||
| 代码 | zytzgg | bmtzgg | bzhd |`,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const url = `https://www.swpu.edu.cn/bgw2/${ctx.req.param('code')}.htm`;
|
||||
async function handler(ctx): Promise<Data> {
|
||||
const url = `https://www.swpu.edu.cn/bgw/${ctx.req.param('code')}.htm`;
|
||||
|
||||
const res = await got.get(url);
|
||||
const $ = load(res.data);
|
||||
|
|
@ -43,39 +43,37 @@ async function handler(ctx) {
|
|||
const title = $('.title').text();
|
||||
|
||||
// 获取标题、时间及链接
|
||||
const items = [];
|
||||
$('.notice > ul > li > a').each((i, elem) => {
|
||||
items.push({
|
||||
const items: DataItem[] = $('.notice > ul > li > a')
|
||||
.toArray()
|
||||
.map((elem) => ({
|
||||
title: $(elem.children[0]).text(),
|
||||
pubDate: timezone(parseDate($(elem.children[1]).text()), +8),
|
||||
link: joinUrl('https://www.swpu.edu.cn', $(elem).attr('href')), // 实际获得连接 "../info/1312/17891.htm"
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
// 请求全文
|
||||
const out = await Promise.all(
|
||||
items.map(async (item) => {
|
||||
const $ = await cache.tryGet(item.link, async () => {
|
||||
const res = await got.get(item.link);
|
||||
return load(res.data);
|
||||
});
|
||||
|
||||
if ($('title').text().startsWith('系统提示')) {
|
||||
item.author = '系统';
|
||||
item.description = '无权访问';
|
||||
} else {
|
||||
item.author = '办公网';
|
||||
item.description = $('.v_news_content').html();
|
||||
for (const elem of $('.v_news_content p')) {
|
||||
if ($(elem).css('text-align') === 'right') {
|
||||
item.author = $(elem).text();
|
||||
break;
|
||||
const out: DataItem[] = await Promise.all(
|
||||
items.map(
|
||||
async (item: DataItem) =>
|
||||
(await cache.tryGet(item.link!, async () => {
|
||||
const resp = await got.get(item.link);
|
||||
const $ = load(resp.data);
|
||||
if ($('title').text().startsWith('系统提示')) {
|
||||
item.author = '系统';
|
||||
item.description = '无权访问';
|
||||
} else {
|
||||
item.author = '办公网';
|
||||
item.description = $('.v_news_content').html()!;
|
||||
for (const elem of $('.v_news_content p')) {
|
||||
if ($(elem).css('text-align') === 'right') {
|
||||
item.author = $(elem).text();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})) as DataItem
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Route } from '@/types';
|
||||
import { DataItem, Route, Data } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import { joinUrl } from './utils';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
|
@ -34,7 +34,7 @@ export const route: Route = {
|
|||
| 代码 | tzgg | xwbd | sdsy |`,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
async function handler(ctx): Promise<Data> {
|
||||
const url = `https://www.swpu.edu.cn/dean/${ctx.req.param('code')}.htm`;
|
||||
|
||||
const res = await got.get(url);
|
||||
|
|
@ -44,39 +44,37 @@ async function handler(ctx) {
|
|||
title = title.substring(title.indexOf(':') + 1);
|
||||
|
||||
// 获取标题、时间及链接
|
||||
const items = [];
|
||||
$('.r_list > ul > li').each((i, elem) => {
|
||||
items.push({
|
||||
const items: DataItem[] = $('.r_list > ul > li')
|
||||
.toArray()
|
||||
.map((elem) => ({
|
||||
title: $('label:eq(0)', elem).text().trim(),
|
||||
link: joinUrl('https://www.swpu.edu.cn/dean/', $('a', elem).attr('href')),
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
// 请求全文
|
||||
const out = await Promise.all(
|
||||
items.map(async (item) => {
|
||||
const $ = await cache.tryGet(item.link, async () => {
|
||||
const res = await got.get(item.link);
|
||||
return load(res.data);
|
||||
});
|
||||
|
||||
if ($('title').text().startsWith('系统提示')) {
|
||||
item.author = '系统';
|
||||
item.description = '无权访问';
|
||||
} else {
|
||||
item.author = '教务处';
|
||||
item.description = $('.v_news_content').html();
|
||||
item.pubDate = timezone(parseDate($('#lbDate').text(), '更新时间:YYYY年MM月DD日'), +8);
|
||||
for (const elem of $('.v_news_content p')) {
|
||||
if ($(elem).css('text-align') === 'right') {
|
||||
item.author = $(elem).text();
|
||||
break;
|
||||
items.map(
|
||||
async (item) =>
|
||||
(await cache.tryGet(item.link!, async () => {
|
||||
const resp = await got.get(item.link);
|
||||
const $ = load(resp.data);
|
||||
if ($('title').text().startsWith('系统提示')) {
|
||||
item.author = '系统';
|
||||
item.description = '无权访问';
|
||||
} else {
|
||||
item.author = '教务处';
|
||||
item.description = $('.v_news_content').html()!;
|
||||
item.pubDate = timezone(parseDate($('#lbDate').text(), '更新时间:YYYY年MM月DD日'), +8);
|
||||
for (const elem of $('.v_news_content p')) {
|
||||
if ($(elem).css('text-align') === 'right') {
|
||||
item.author = $(elem).text();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})) as DataItem
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Route } from '@/types';
|
||||
import { DataItem, Route, Data } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import { joinUrl } from './utils';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
|
@ -34,7 +34,7 @@ export const route: Route = {
|
|||
| 代码 | 1122 | 1156 |`,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
async function handler(ctx): Promise<Data> {
|
||||
// 移除 urltype=tree.TreeTempUrl 虽然也能顺利访问页面,
|
||||
// 但标题会缺失,而且在其他地方定位提取标题也比较麻烦。
|
||||
const url = `https://www.swpu.edu.cn/dxy/list1.jsp?urltype=tree.TreeTempUrl&wbtreeid=${ctx.req.param('code')}`;
|
||||
|
|
@ -46,39 +46,37 @@ async function handler(ctx) {
|
|||
title = title.substring(0, title.indexOf('-'));
|
||||
|
||||
// 获取标题、时间及链接
|
||||
const items = [];
|
||||
$('tr[height="20"]').each((i, elem) => {
|
||||
items.push({
|
||||
const items: DataItem[] = $('tr[height="20"]')
|
||||
.toArray()
|
||||
.map((elem) => ({
|
||||
title: $('a[title]', elem).text().trim(),
|
||||
pubDate: timezone(parseDate($('td:eq(1)', elem).text(), 'YYYY年MM月DD日'), +8),
|
||||
link: joinUrl('https://www.swpu.edu.cn/dxy/', $('a[title]', elem).attr('href')),
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
// 请求全文
|
||||
const out = await Promise.all(
|
||||
items.map(async (item) => {
|
||||
const $ = await cache.tryGet(item.link, async () => {
|
||||
const res = await got.get(item.link);
|
||||
return load(res.data);
|
||||
});
|
||||
|
||||
if ($('title').text().startsWith('系统提示')) {
|
||||
item.author = '系统';
|
||||
item.description = '无权访问';
|
||||
} else {
|
||||
item.author = '电气信息学院';
|
||||
item.description = $('.v_news_content').html();
|
||||
for (const elem of $('.v_news_content p')) {
|
||||
if ($(elem).css('text-align') === 'right') {
|
||||
item.author = $(elem).text();
|
||||
break;
|
||||
items.map(
|
||||
async (item) =>
|
||||
(await cache.tryGet(item.link!, async () => {
|
||||
const resp = await got.get(item.link);
|
||||
const $ = load(resp.data);
|
||||
if ($('title').text().startsWith('系统提示')) {
|
||||
item.author = '系统';
|
||||
item.description = '无权访问';
|
||||
} else {
|
||||
item.author = '电气信息学院';
|
||||
item.description = $('.v_news_content').html()!;
|
||||
for (const elem of $('.v_news_content p')) {
|
||||
if ($(elem).css('text-align') === 'right') {
|
||||
item.author = $(elem).text();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})) as DataItem
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Route } from '@/types';
|
||||
import { DataItem, Route, Data } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import { joinUrl } from './utils';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
|
@ -25,7 +25,7 @@ export const route: Route = {
|
|||
target: '',
|
||||
},
|
||||
],
|
||||
name: '计算机科学学院',
|
||||
name: '计算机与软件学院',
|
||||
maintainers: ['CYTMWIA'],
|
||||
handler,
|
||||
url: 'swpu.edu.cn/',
|
||||
|
|
@ -34,7 +34,7 @@ export const route: Route = {
|
|||
| 代码 | tzgg | xwsd |`,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
async function handler(ctx): Promise<Data> {
|
||||
const url = `https://www.swpu.edu.cn/scs/index/${ctx.req.param('code')}.htm`;
|
||||
|
||||
const res = await got.get(url);
|
||||
|
|
@ -43,45 +43,43 @@ async function handler(ctx) {
|
|||
const title = $('.r_list > h3').text();
|
||||
|
||||
// 获取标题、时间及链接
|
||||
const items = [];
|
||||
$('.main_conRCb > ul > li').each((i, elem) => {
|
||||
items.push({
|
||||
const items: DataItem[] = $('.main_conRCb > ul > li')
|
||||
.toArray()
|
||||
.map((elem) => ({
|
||||
title: $('em', elem).text().trim(),
|
||||
pubDate: timezone(parseDate($('span', elem).text()), +8),
|
||||
link: joinUrl('https://www.swpu.edu.cn/scs/index/', $('a', elem).attr('href')),
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
// 请求全文
|
||||
const out = await Promise.all(
|
||||
items.map(async (item) => {
|
||||
const $ = await cache.tryGet(item.link, async () => {
|
||||
const res = await got.get(item.link);
|
||||
return load(res.data);
|
||||
});
|
||||
|
||||
if ($('title').text().startsWith('系统提示')) {
|
||||
item.author = '系统';
|
||||
item.description = '无权访问';
|
||||
} else {
|
||||
item.author = '计算机科学学院';
|
||||
item.description = $('.v_news_content').html();
|
||||
for (const elem of $('.v_news_content p')) {
|
||||
if ($(elem).css('text-align') === 'right') {
|
||||
item.author = $(elem).text();
|
||||
break;
|
||||
items.map(
|
||||
async (item) =>
|
||||
(await cache.tryGet(item.link!, async () => {
|
||||
const resp = await got.get(item.link);
|
||||
const $ = load(resp.data);
|
||||
if ($('title').text().startsWith('系统提示')) {
|
||||
item.author = '系统';
|
||||
item.description = '无权访问';
|
||||
} else {
|
||||
item.author = '计算机与软件学院';
|
||||
item.description = $('.v_news_content').html()!;
|
||||
for (const elem of $('.v_news_content p')) {
|
||||
if ($(elem).css('text-align') === 'right') {
|
||||
item.author = $(elem).text();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})) as DataItem
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
title: `西南石油大学计算机科学学院 ${title}`,
|
||||
title: `西南石油大学计算机与软件学院 ${title}`,
|
||||
link: url,
|
||||
description: `西南石油大学计算机科学学院 ${title}`,
|
||||
description: `西南石油大学计算机与软件学院 ${title}`,
|
||||
language: 'zh-CN',
|
||||
item: out,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue