Skip to content

Commit

Permalink
feat(route): add hdu/auto (#18046)
Browse files Browse the repository at this point in the history
  • Loading branch information
jalenzz authored Jan 5, 2025
1 parent 384712d commit 521313f
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 1 deletion.
27 changes: 27 additions & 0 deletions lib/routes/hdu/auto/graduate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Route } from '@/types';
import { fetchAutoNews } from './utils';

export const route: Route = {
path: '/auto/graduate',
categories: ['university'],
example: '/hdu/auto/graduate',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '自动化学院 - 研究生教育通知',
maintainers: ['jalenzz'],
handler: () => fetchAutoNews('3754/list.htm', '研究生教育'),
description: '杭州电子科技大学自动化学院研究生教育',
radar: [
{
source: ['auto.hdu.edu.cn/main.htm', 'auto.hdu.edu.cn/3754/list.htm'],
target: '/auto/graduate',
},
],
};
27 changes: 27 additions & 0 deletions lib/routes/hdu/auto/notice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Route } from '@/types';
import { fetchAutoNews } from './utils';

export const route: Route = {
path: '/auto',
categories: ['university'],
example: '/hdu/auto',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '自动化学院 - 通知公告',
maintainers: ['jalenzz'],
handler: () => fetchAutoNews('3779/list.htm', '通知公告'),
description: '杭州电子科技大学自动化学院通知公告',
radar: [
{
source: ['auto.hdu.edu.cn/main.htm', 'auto.hdu.edu.cn/3779/list.htm'],
target: '/auto',
},
],
};
27 changes: 27 additions & 0 deletions lib/routes/hdu/auto/student.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Route } from '@/types';
import { fetchAutoNews } from './utils';

export const route: Route = {
path: '/auto/student',
categories: ['university'],
example: '/hdu/auto/student',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '自动化学院 - 学生工作',
maintainers: ['jalenzz'],
handler: () => fetchAutoNews('3726/list.htm', '学生工作'),
description: '杭州电子科技大学自动化学院学生工作',
radar: [
{
source: ['auto.hdu.edu.cn/main.htm', 'auto.hdu.edu.cn/3726/list.htm'],
target: '/auto/student',
},
],
};
27 changes: 27 additions & 0 deletions lib/routes/hdu/auto/undergraduate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Route } from '@/types';
import { fetchAutoNews } from './utils';

export const route: Route = {
path: '/auto/undergraduate',
categories: ['university'],
example: '/hdu/auto/undergraduate',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '自动化学院 - 本科教学',
maintainers: ['jalenzz'],
handler: () => fetchAutoNews('3745/list.htm', '本科教学'),
description: '杭州电子科技大学自动化学院本科教学',
radar: [
{
source: ['auto.hdu.edu.cn/main.htm', 'auto.hdu.edu.cn/3745/list.htm'],
target: '/auto/undergraduate',
},
],
};
51 changes: 51 additions & 0 deletions lib/routes/hdu/auto/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Data, DataItem } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';

const BASE_URL = 'https://auto.hdu.edu.cn';

export const fetchAutoNews = async (path: string, title: string): Promise<Data> => {
const link = `${BASE_URL}/${path}`;
const response = await got(link);
const $ = load(response.data);

const list = $('.rightlist')
.toArray()
.map((item): DataItem => {
const $item = $(item);
const $a = $item.find('.newstitle a');
const href = $a.attr('href');
const title = $a.text().trim();
const dateMatch = $item
.find('.newsinfo')
.text()
.match(/(\d{4}\/\d{2}\/\d{2})/);
const brief = $item.find('.newsbrief').text().trim();

return {
title: title || '无标题',
link: href ? new URL(href, BASE_URL).href : BASE_URL,
pubDate: dateMatch ? parseDate(dateMatch[1], 'YYYY/MM/DD') : undefined,
description: brief || '',
};
});

const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const { data } = await got(item.link);
const $detail = load(data);
const description = $detail('.wp_articlecontent').html();
return { ...item, description: description || item.description };
})
)
);

return {
title: `杭州电子科技大学自动化学院 - ${title}`,
link,
item: items as DataItem[],
};
};
2 changes: 1 addition & 1 deletion lib/routes/hdu/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '杭州电子科技大学',
url: 'computer.hdu.edu.cn',
url: 'hdu.edu.cn',
lang: 'zh-CN',
};

0 comments on commit 521313f

Please sign in to comment.