feat(routes/buct): add route '北京化工大学' (#18306)

* routes add buct

* 'fix warning'

* fix warning

* fix review suggestion
This commit is contained in:
Epic-creeper 2025-02-11 00:36:31 +08:00 committed by GitHub
parent 727b834fc4
commit 46368b2c6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 222 additions and 0 deletions

58
lib/routes/buct/cist.ts Normal file
View File

@ -0,0 +1,58 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
export const route: Route = {
path: '/cist',
categories: ['university'],
example: '/buct/cist',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [{ source: ['cist.buct.edu.cn/xygg/list.htm', 'cist.buct.edu.cn/xygg/main.htm'], target: '/cist' }],
name: '信息学院',
maintainers: ['Epic-Creeper'],
handler,
url: 'buct.edu.cn/',
};
async function handler() {
const rootUrl = 'https://cist.buct.edu.cn';
const currentUrl = `${rootUrl}/xygg/list.htm`;
const response = await got.get(currentUrl);
const $ = load(response.data);
const list = $('ul.wp_article_list > li.list_item')
.toArray()
.map((item) => ({
pubDate: $(item).find('.Article_PublishDate').text(),
title: $(item).find('a').attr('title'),
link: `${rootUrl}${$(item).find('a').attr('href')}`,
}));
const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await got.get(item.link);
const content = load(detailResponse.data);
item.description = content('.wp_articlecontent').html();
return item;
})
)
);
return {
title: $('title').text(),
link: currentUrl,
item: items,
};
}

93
lib/routes/buct/gr.ts Normal file
View File

@ -0,0 +1,93 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import type { Context } from 'hono';
export const route: Route = {
path: '/gr/:type',
categories: ['university'],
example: '/buct/gr/jzml',
parameters: {
type: {
description: '信息类型可选值tzgg通知公告jzml简章目录xgzc相关政策',
options: [
{ value: 'tzgg', label: '通知公告' },
{ value: 'jzml', label: '简章目录' },
{ value: 'xgzc', label: '相关政策' },
],
},
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{ source: ['graduate.buct.edu.cn/1392/list.htm'], target: '/gr/tzgg' },
{ source: ['graduate.buct.edu.cn/jzml/list.htm'], target: '/gr/jzml' },
{ source: ['graduate.buct.edu.cn/1393/list.htm'], target: '/gr/xgzc' },
],
name: '研究生院',
maintainers: ['Epic-Creeper'],
handler,
url: 'buct.edu.cn/',
};
async function handler(ctx: Context) {
const type = ctx.req.param('type');
const rootUrl = 'https://graduate.buct.edu.cn';
let currentUrl;
switch (type) {
case 'tzgg':
currentUrl = `${rootUrl}/1392/list.htm`;
break;
case 'jzml':
currentUrl = `${rootUrl}/jzml/list.htm`;
break;
case 'xgzc':
currentUrl = `${rootUrl}/1393/list.htm`;
break;
default:
throw new Error('Invalid type parameter');
}
const response = await got.get(currentUrl);
const $ = load(response.data);
const list = $('ul.wp_article_list > li.list_item')
.toArray()
.map((item) => ({
pubDate: $(item).find('.Article_PublishDate').text(),
title: $(item).find('a').attr('title'),
link: `${rootUrl}${$(item).find('a').attr('href')}`,
}));
const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await got.get(item.link);
const content = load(detailResponse.data);
item.description = content('.wp_articlecontent').html();
return item;
})
)
);
return {
title: $('title').text(),
link: currentUrl,
item: items,
};
}

64
lib/routes/buct/jwc.ts Normal file
View File

@ -0,0 +1,64 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
export const route: Route = {
path: '/jwc',
categories: ['university'],
example: '/buct/jwc',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [{ source: ['jiaowuchu.buct.edu.cn/610/list.htm', 'jiaowuchu.buct.edu.cn/611/main.htm'], target: '/jwc' }],
name: '教务处',
maintainers: ['Epic-Creeper'],
handler,
url: 'buct.edu.cn/',
};
async function handler() {
const rootUrl = 'https://jiaowuchu.buct.edu.cn';
const currentUrl = `${rootUrl}/610/list.htm`;
const response = await got.get(currentUrl);
const $ = load(response.data);
const list = $('div.list02 ul > li')
.not('#wp_paging_w66 li')
.toArray()
.map((item) => ({
pubDate: $(item).find('span').text(),
title: $(item).find('a').attr('title'),
link: `${rootUrl}${$(item).find('a').attr('href')}`,
}));
const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await got.get(item.link);
const content = load(detailResponse.data);
const iframeSrc = content('.wp_pdf_player').attr('pdfsrc');
if (iframeSrc) {
const pdfUrl = `${rootUrl}${iframeSrc}`;
item.description = `此页面为PDF文档<a href="${new URL(pdfUrl, rootUrl)}">点击查看pdf</a>`;
return item;
}
item.description = content('.rt_zhengwen').html();
return item;
})
)
);
return {
title: $('title').text(),
link: currentUrl,
item: items,
};
}

View File

@ -0,0 +1,7 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: '北京化工大学',
url: 'buct.edu.cn',
lang: 'zh-CN',
};