Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): Add泉州师范学院 #17329

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,8 @@ router.get('/jx3/:caty?', lazyloadRouteHandler('./routes/jx3/news'));

// 泉州市跨境电子商务协会
router.get('/qzcea/:caty?', lazyloadRouteHandler('./routes/qzcea/index'));
// 泉州师范学院
router.get('/qztc/:type', lazyloadRouteHandler('./routes/universities/qztc/index'));

// CGTN
router.get('/cgtn/most/:type?/:time?', lazyloadRouteHandler('./routes/cgtn/most'));
Expand Down
112 changes: 112 additions & 0 deletions lib/routes/qztc/home/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { Data, Route } from '@/types';
import cache from '@/utils/cache';
import { parseDate } from '@/utils/parse-date';
import { load } from 'cheerio';
import ofetch from '@/utils/ofetch';
import timezone from '@/utils/timezone';

const rootUrl = 'https://www.qztc.edu.cn/';
const host = 'www.qztc.edu.cn';
const name = '泉州师范学院-首页';

export const route: Route = {
path: '/home/:type',
categories: ['university'],
example: '/qztc/home/2093',
parameters: { type: '分类,见下表' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name,
maintainers: ['iQNRen'],
url: 'www.qztc.edu.cn',
handler,
radar: [
{
source: ['www.qztc.edu.cn/:type/list.htm'],
target: '/home/:type',
},
],
description: `| 板块 | 参数 |
| ------- | ------- |
| 泉师新闻 | 2093 |
| 通知公告 | 2094 |
| 采购公告 | 2095 |
| 学术资讯 | xszx |
| 招聘信息 | 2226 |
`,
};

async function handler(ctx) {
const type = ctx.req.param('type');
// const type = Number.parseInt(ctx.req.param('type'));
const response = await ofetch(rootUrl + type + '/list.htm');
const $ = load(response);

const list = $('.news.clearfix')
.toArray()
.map((item) => {
const cheerioItem = $(item);
const a = cheerioItem.find('a');

try {
const title = a.attr('title') || '';
let link = a.attr('href');
if (!link) {
link = '';
} else if (!link.startsWith('http')) {
link = rootUrl.slice(0, -1) + link;
}
const pubDate = timezone(parseDate(cheerioItem.find('.news_meta').text()), +8);

return {
title,
link,
pubDate,
};
} catch {
return {
title: '',
link: '',
pubDate: Date.now(),
};
}
})
.filter((item) => item.title && item.link);

const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const newItem = {
...item,
description: '',
};
if (host === new URL(item.link).hostname) {
if (new URL(item.link).pathname.startsWith('/_upload')) {
// 链接为一个文件,直接返回链接
newItem.description = item.link;
} else {
const response = await ofetch(item.link);
const $ = load(response);
newItem.description = $('.wp_articlecontent').html() || '';
}
} else {
// 涉及到其他站点,不方便做统一的 html 解析,直接返回链接
newItem.description = item.link;
}
return newItem;
})
)
);

return {
title: $('head > title').text() + ` - ${name}`,
link: rootUrl + type + '/list.htm',
item: items,
} as Data;
}
121 changes: 121 additions & 0 deletions lib/routes/qztc/jwc/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { Data, Route } from '@/types';
import cache from '@/utils/cache';
import { parseDate } from '@/utils/parse-date';
import { load } from 'cheerio';
import ofetch from '@/utils/ofetch';
import timezone from '@/utils/timezone';

const rootUrl = 'https://www.qztc.edu.cn/jwc/';
const host = 'www.qztc.edu.cn';
const name = '泉州师范学院-教务处';

export const route: Route = {
path: '/jwc/:type',
categories: ['university'],
example: '/qztc/jwc/jwdt',
parameters: { type: '分类,见下表' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name,
maintainers: ['iQNRen'],
url: 'www.qztc.edu.cn',
handler,
radar: [
{
source: ['www.qztc.edu.cn/jwc/:type/list.htm'],
target: '/jwc/:type',
},
],
description: `| 板块 | 参数 |
| ------- | ------- |
| 教务动态 | jwdt |
| 首 页 | 1020 |
| 岗位介绍 | 1021 |
| 管理文件 | 1022 |
| 教学教改 | 1023 |
| 办事指南 | 1024 |
| 通知公告 | 1025 |
| 下载中心 | 1026 |
| 对外交流 | 1027 |
| 政策文件 | 1028 |
| 会议纪要 | 1029 |
`,
// | 学院简介 | 1949 |
// | 学院领导 | 1950 |
// | 组织机构 | 1951 |
};

async function handler(ctx) {
const type = ctx.req.param('type');
// const type = Number.parseInt(ctx.req.param('type'));
const response = await ofetch(rootUrl + type + '/list.htm');
const $ = load(response);

const list = $('.news.clearfix')
.toArray()
.map((item) => {
const cheerioItem = $(item);
const a = cheerioItem.find('a');

try {
const title = a.attr('title') || '';
let link = a.attr('href');
if (!link) {
link = '';
} else if (!link.startsWith('http')) {
link = rootUrl.slice(0, -1) + link;
}
const pubDate = timezone(parseDate(cheerioItem.find('.news_meta').text()), +8);

return {
title,
link,
pubDate,
};
} catch {
return {
title: '',
link: '',
pubDate: Date.now(),
};
}
})
.filter((item) => item.title && item.link);

const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const newItem = {
...item,
description: '',
};
if (host === new URL(item.link).hostname) {
if (new URL(item.link).pathname.startsWith('/_upload')) {
// 链接为一个文件,直接返回链接
newItem.description = item.link;
} else {
const response = await ofetch(item.link);
const $ = load(response);
newItem.description = $('.wp_articlecontent').html() || '';
}
} else {
// 涉及到其他站点,不方便做统一的 html 解析,直接返回链接
newItem.description = item.link;
}
return newItem;
})
)
);

return {
title: $('head > title').text() + ` - ${name}`,
link: rootUrl + type + '/list.htm',
item: items,
} as Data;
}
6 changes: 6 additions & 0 deletions lib/routes/qztc/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '泉州师范学院',
url: 'www.qztc.edu.cn',
};
121 changes: 121 additions & 0 deletions lib/routes/qztc/sjxy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { Data, Route } from '@/types';
import cache from '@/utils/cache';
import { parseDate } from '@/utils/parse-date';
import { load } from 'cheerio';
import ofetch from '@/utils/ofetch';
import timezone from '@/utils/timezone';

const rootUrl = 'https://www.qztc.edu.cn/sjxy/';
const host = 'www.qztc.edu.cn';
const name = '泉州师范学院-数学与计算机科学学院 软件学院';

export const route: Route = {
path: '/sjxy/:type',
categories: ['university'],
example: '/qztc/sjxy/1939',
parameters: { type: '分类,见下表' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name,
maintainers: ['iQNRen'],
url: 'www.qztc.edu.cn',
handler,
radar: [
{
source: ['www.qztc.edu.cn/sjxy/:type/list.htm'],
target: '/sjxy/:type',
},
],
description: `| 板块 | 参数 |
| ------- | ------- |
| 学院概况 | 1938 |
| 学院动态 | 1939 |
| 学科建设 | 1940 |
| 教学教务 | 1941 |
| 人才培养 | 1942 |
| 科研工作 | 1943 |
| 党群工作 | 1944 |
| 团学工作 | 1945 |
| 资料下载 | 1947 |
| 采购信息 | 1948 |
| 信息公开 | xxgk |
`,
// | 学院简介 | 1949 |
// | 学院领导 | 1950 |
// | 组织机构 | 1951 |
};

async function handler(ctx) {
const type = ctx.req.param('type');
// const type = Number.parseInt(ctx.req.param('type'));
const response = await ofetch(rootUrl + type + '/list.htm');
const $ = load(response);

const list = $('.news.clearfix')
.toArray()
.map((item) => {
const cheerioItem = $(item);
const a = cheerioItem.find('a');

try {
const title = a.attr('title') || '';
let link = a.attr('href');
if (!link) {
link = '';
} else if (!link.startsWith('http')) {
link = rootUrl.slice(0, -1) + link;
}
const pubDate = timezone(parseDate(cheerioItem.find('.news_meta').text()), +8);

return {
title,
link,
pubDate,
};
} catch {
return {
title: '',
link: '',
pubDate: Date.now(),
};
}
})
.filter((item) => item.title && item.link);

const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const newItem = {
...item,
description: '',
};
if (host === new URL(item.link).hostname) {
if (new URL(item.link).pathname.startsWith('/_upload')) {
// 链接为一个文件,直接返回链接
newItem.description = item.link;
} else {
const response = await ofetch(item.link);
const $ = load(response);
newItem.description = $('.wp_articlecontent').html() || '';
}
} else {
// 涉及到其他站点,不方便做统一的 html 解析,直接返回链接
newItem.description = item.link;
}
return newItem;
})
)
);

return {
title: $('head > title').text() + ` - ${name}`,
link: rootUrl + type + '/list.htm',
item: items,
} as Data;
}
Loading