feat(route): Add 北京交通大学研究生院通知和西南交通大学地球科学与工程学院研究生通知路由 (#15608)

* feat: 根据V2规范重新编写了北京交通大学研究生院的路由规则

* fix: 修复标题错误

* feat: 添加西南交通大学地球科学与工程学院研究生教育路由规则

* fix: 修复example编写错误

* style: 变量命名风格修改为camelCase;删除多余的heading;修改description缩进为2空格;
refactor: 删除弃用的路由;删除不必要的cache参数传递;

---------

Co-authored-by: pull[bot] <39814207+pull[bot]@users.noreply.github.com>
This commit is contained in:
E1nzbern 2024-05-19 18:36:34 +08:00 committed by GitHub
parent 1b78fcedd1
commit a023bc4e99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 308 additions and 130 deletions

View File

@ -1,130 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const type = ctx.params.type;
const struct = {
zs: {
selector: {
list: '.mainleft_box li',
},
url: 'https://gs.bjtu.edu.cn/cms/zszt/item/?tag=1',
name: '招生 - 北京交通大学研究生院',
},
noti: {
selector: {
list: '.tab-content li',
},
url: 'https://gs.bjtu.edu.cn/cms/item/?tag=2',
name: '通知公告 - 北京交通大学研究生院',
},
news: {
selector: {
list: '.tab-content li',
},
url: 'https://gs.bjtu.edu.cn/cms/item/?tag=3',
name: '新闻动态 - 北京交通大学研究生院',
},
zsxc: {
selector: {
list: '.tab-content li',
},
url: 'https://gs.bjtu.edu.cn/cms/item/?tag=4',
name: '招生宣传 - 北京交通大学研究生院',
},
py: {
selector: {
list: '.tab-content li',
},
url: 'https://gs.bjtu.edu.cn/cms/item/?tag=5',
name: '培养 - 北京交通大学研究生院',
},
xw: {
selector: {
list: '.tab-content li',
},
url: 'https://gs.bjtu.edu.cn/cms/item/?tag=7',
name: '学位 - 北京交通大学研究生院',
},
ygbtzgg: {
selector: {
list: '.tab-content li',
},
url: 'https://gs.bjtu.edu.cn/cms/item/?tag=9',
name: '通知公告 - 研工部 - 北京交通大学研究生院',
},
ygbnews: {
selector: {
list: '.tab-content li',
},
url: 'https://gs.bjtu.edu.cn/cms/item/?tag=10',
name: '新闻动态 - 研工部 - 北京交通大学研究生院',
},
all: {
selector: {
list: '.tab-content li',
},
url: 'https://gs.bjtu.edu.cn/cms/item/?tag=12',
name: '所有文章 - 北京交通大学研究生院',
},
bszs: {
selector: {
list: '.mainleft_box li',
},
url: 'https://gs.bjtu.edu.cn/cms/zszt/item/?cat=2',
name: '博士招生 - 北京交通大学研究生院',
},
sszs: {
selector: {
list: '.mainleft_box li',
},
url: 'https://gs.bjtu.edu.cn/cms/zszt/item/?cat=3',
name: '硕士招生 - 北京交通大学研究生院',
},
zsjz: {
selector: {
list: '.mainleft_box li',
},
url: 'https://gs.bjtu.edu.cn/cms/zszt/item/?cat=4',
name: '招生简章 - 北京交通大学研究生院',
},
zcfg: {
selector: {
list: '.mainleft_box li',
},
url: 'https://gs.bjtu.edu.cn/cms/zszt/item/?cat=5',
name: '政策法规 - 北京交通大学研究生院',
},
};
const url = struct[type].url;
const response = await got({
method: 'get',
url,
});
const data = response.data;
const $ = cheerio.load(data);
const list = $(struct[type].selector.list);
ctx.state.data = {
title: struct[type].name,
link: url,
description: '北京交通大学研究生院',
item:
list &&
list
.map((index, item) => {
item = $(item);
const date = new Date(Date.parse(item.find('li span').text().slice(1, 11).replaceAll('-', '/')));
const bj_date = date.getTime() / 1000 + 8 * 60 * 60;
const title = item
.find('li a')
.text()
.replaceAll(/\[.*?]/g, '');
return { title, description: title, link: item.find('li a').attr('href'), pubDate: new Date(Number.parseInt(bj_date) * 1000) };
})
.get(),
};
};

224
lib/routes/bjtu/gs.ts Normal file
View File

@ -0,0 +1,224 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
const rootURL = 'https://gs.bjtu.edu.cn';
const urlCms = `${rootURL}/cms/item/?tag=`;
const urlZszt = `${rootURL}/cms/zszt/item/?cat=`;
const title = ' - 北京交通大学研究生院';
const zsztRegex = /_zszt/;
const struct = {
noti_zs: {
selector: {
list: '.tab-content li',
},
tag: 1,
name: '通知公告_招生',
},
noti: {
selector: {
list: '.tab-content li',
},
tag: 2,
name: '通知公告',
},
news: {
selector: {
list: '.tab-content li',
},
tag: 3,
name: '新闻动态',
},
zsxc: {
selector: {
list: '.tab-content li',
},
tag: 4,
name: '招生宣传',
},
py: {
selector: {
list: '.tab-content li',
},
tag: 5,
name: '培养',
},
zs: {
selector: {
list: '.tab-content li',
},
tag: 6,
name: '招生',
},
xw: {
selector: {
list: '.tab-content li',
},
tag: 7,
name: '学位',
},
ygb: {
selector: {
list: '.tab-content li',
},
tag: 8,
name: '研工部',
},
ygbtzgg: {
selector: {
list: '.tab-content li',
},
tag: 9,
name: '通知公告 - 研工部',
},
ygbnews: {
selector: {
list: '.tab-content li',
},
tag: 10,
name: '新闻动态 - 研工部',
},
ygbnewscover: {
selector: {
list: '.tab-content li',
},
tag: 11,
name: '新闻封面 - 研工部',
},
all: {
selector: {
list: '.tab-content li',
},
tag: 12,
name: '文章列表',
},
bszs_zszt: {
selector: {
list: '.mainleft_box li',
},
tag: 2,
name: '博士招生 - 招生专题',
},
sszs_zszt: {
selector: {
list: '.mainleft_box li',
},
tag: 3,
name: '硕士招生 - 招生专题',
},
zsjz_zszt: {
selector: {
list: '.mainleft_box li',
},
tag: 4,
name: '招生简章 - 招生专题',
},
zcfg_zszt: {
selector: {
list: '.mainleft_box li',
},
tag: 5,
name: '政策法规 - 招生专题',
},
};
const getItem = (item, selector) => {
const newsInfo = item.find('a');
const newsDate = item
.find('span')
.text()
.match(/\d{4}(-|\/|.)\d{1,2}\1\d{1,2}/)[0];
const infoTitle = newsInfo.text();
const link = rootURL + newsInfo.attr('href');
return cache.tryGet(link, async () => {
const resp = await ofetch(link);
const $$ = load(resp);
const infoText = $$(selector).html();
return {
title: infoTitle,
pubDate: parseDate(newsDate),
link,
description: infoText,
};
}) as any;
};
export const route: Route = {
path: '/gs/:type?',
categories: ['university'],
example: '/bjtu/gs/noti',
parameters: { type: 'Article type' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['gs.bjtu.edu.cn'],
},
],
name: '研究生院',
maintainers: ['E1nzbern'],
handler,
description: `
| | |
| ----------------- | ------------ |
| _招生 | noti_zs |
| | noti |
| | news |
| | zsxc |
| | py |
| | zs |
| | xw |
| | ygb |
| - | ygbtzgg |
| - | ygbnews |
| - | ygbnewscover |
| | all |
| - | bszs_zszt |
| - | sszs_zszt |
| - | zsjz_zszt |
| - | zcfg_zszt |
:::tip
_招生 - -
:::`,
};
async function handler(ctx) {
const { type = 'noti' } = ctx.req.param();
let url = urlCms;
let selectorArticle = 'div.main_left.main_left_list';
if (zsztRegex.test(type)) {
url = urlZszt;
selectorArticle = 'div.mainleft_box';
}
const urlAddr = `${url}${struct[type].tag}`;
const resp = await ofetch(urlAddr);
const $ = load(resp);
const list = $(struct[type].selector.list);
const items = await Promise.all(
list.toArray().map((i) => {
const item = $(i);
return getItem(item, selectorArticle);
})
);
return {
title: `${struct[type].name}${title}`,
link: urlAddr,
item: items,
allowEmpty: true,
};
}

View File

@ -0,0 +1,8 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'Beijing Jiaotong University',
url: 'bjtu.edu.cn',
zh: {
name: '北京交通大学',
},
};

View File

@ -0,0 +1,76 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
const rootURL = 'https://gsee.swjtu.edu.cn';
const urlAddr = `${rootURL}/xwzx/tzgg.htm`;
const getItem = (item) => {
const newsInfo = item.find('dt');
const newsDate = item
.find('dd')
.text()
.match(/\d{4}(-|\/|.)\d{1,2}\1\d{1,2}/)[0];
const infoTitle = newsInfo.text();
const link = rootURL + newsInfo.find('a').last().attr('href').slice(2);
return cache.tryGet(link, async () => {
const resp = await ofetch(link);
const $$ = load(resp);
const infoText = $$('.article').html();
return {
title: infoTitle,
pubDate: parseDate(newsDate),
link,
description: infoText,
};
}) as any;
};
export const route: Route = {
path: '/gsee/yjs',
categories: ['university'],
example: '/swjtu/gsee/yjs',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['gsee.swjtu.edu.cn/'],
},
],
name: '地球科学与工程学院',
maintainers: ['E1nzbern'],
handler,
description: `研究生教育通知公告`,
};
async function handler() {
const resp = await ofetch(urlAddr);
const $ = load(resp);
const list = $('dl');
const items = await Promise.all(
list.toArray().map((i) => {
const item = $(i);
return getItem(item);
})
);
return {
title: '西南交大地学学院-研究生通知',
link: urlAddr,
item: items,
allowEmpty: true,
};
}