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 山青学生在线、山大研工部、山大国际网站 #16812

Merged
merged 9 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
80 changes: 80 additions & 0 deletions lib/routes/sdu/gjsw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import { finishArticleItem } from '@/utils/wechat-mp';

const host = 'https://www.ipo.sdu.edu.cn/';

const typeMap = {
tzgg: {
title: '通知公告',
url: 'tzgg.htm',
},
};

export const route: Route = {
path: '/gjsw/:type?',
categories: ['university'],
example: '/sdu/gjsw/tzgg',
parameters: { type: '默认为`tzgg`' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '国际事务部',
maintainers: ['kukeya'],
handler,
description: `| 通知公告 |
| -------- |
| tzgg | `,
};

async function handler(ctx) {
const type = ctx.req.param('type') ?? 'tzgg';

const link = new URL(typeMap[type].url, host).href;
const response = await got(link);

const $ = load(response.data);

let item = $('.dqlb ul li')
TonyRL marked this conversation as resolved.
Show resolved Hide resolved
.toArray()
.map((e) => {
e = $(e);
const a = e.find('a');
return {
title: a.text().trim(),
TonyRL marked this conversation as resolved.
Show resolved Hide resolved
link: a.attr('href').startsWith('wdhcontent') ? host + a.attr('href') : a.attr('href'),
pubDate: parseDate(e.find('.fr').text().trim(), 'YYYY-MM-DD'),
};
});

item = await Promise.all(
item.map((item) =>
cache.tryGet(item.link, async () => {
const hostname = new URL(item.link).hostname;
if (hostname === 'mp.weixin.qq.com') {
return finishArticleItem(item);
}
const response = await got(item.link);
const $ = load(response.data);
item.description = $('.v_news_content').html();

return item;
})
)
);

return {
title: `山东大学国际事务部${typeMap[type].title}`,
description: $('title').text(),
link,
item,
};
}
99 changes: 99 additions & 0 deletions lib/routes/sdu/qd/xszxqd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import { finishArticleItem } from '@/utils/wechat-mp';

const host = 'https://www.onlineqd.sdu.edu.cn/';

const typeMap = {
'xttz-yjs': {
title: '学团通知-研究生',
url: 'list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1027',
},
'xttz-bks': {
title: '学团通知-本科生',
url: 'list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1025',
},
'xttz-tx': {
title: '学团通知-团学',
url: 'list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1026',
},
'xttz-xl': {
title: '学团通知-心理',
url: 'list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1029',
},
xtyw: {
title: '学团要闻',
url: 'list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1008',
},
};

export const route: Route = {
path: '/qd/xszxqd/:type?',
categories: ['university'],
example: '/sdu/qd/xszxqd/xtyw',
parameters: { type: '默认为`xtyw`' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '学生在线(青岛)',
maintainers: ['kukeya'],
handler,
description: `| 学团通知-研究生 | 学团通知-本科生 | 学团通知-团学 | 学团通知-心理 | 学团要闻
| -------- | -------- |-------- |-------- |-------- |
| xttz-yjs | xttz-bks | xttz-tx | xttz-xl | xtyw |`,
};

async function handler(ctx) {
const type = ctx.req.param('type') ?? 'xtyw';
const link = new URL(typeMap[type].url, host).href;

const response = await got(link);

const $ = load(response.data);

let item = $('.list_box li')
.toArray()
.map((e) => {
e = $(e);
const a = e.find('a');
let link = '';
link = a.attr('href').startsWith('tz_content') || a.attr('href').startsWith('content') ? host + a.attr('href') : a.attr('href');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let link = '';
link = a.attr('href').startsWith('tz_content') || a.attr('href').startsWith('content') ? host + a.attr('href') : a.attr('href');
const link = a.attr('href').startsWith('tz_content') || a.attr('href').startsWith('content') ? host + a.attr('href') : a.attr('href');

link is not reassigned afterwards

return {
title: a.text().trim(),
link,
pubDate: parseDate(e.find('span').text().trim(), 'YYYY-MM-DD'),
};
});

item = await Promise.all(
item.map((item) =>
cache.tryGet(item.link, async () => {
const hostname = new URL(item.link).hostname;
if (hostname === 'mp.weixin.qq.com') {
return finishArticleItem(item);
}
const response = await got(item.link);
const $ = load(response.data);
item.description = $('.v_news_content').html();

return item;
})
)
);

return {
title: `山东大学学生在线(青岛)${typeMap[type].title}`,
description: $('title').text(),
link,
item,
icon: 'https://www.onlineqd.sdu.edu.cn/img/logo.png',
};
}
91 changes: 91 additions & 0 deletions lib/routes/sdu/ygb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import { finishArticleItem } from '@/utils/wechat-mp';

const host = 'https://www.ygb.sdu.edu.cn/';

const typeMap = {
zytz: {
title: '重要通知',
url: 'zytz.htm',
},
glfw: {
title: '管理服务',
url: 'glfw.htm',
},
cxsj: {
title: '创新实践',
url: 'cxsj.htm',
},
};

export const route: Route = {
path: '/ygb/:type?',
categories: ['university'],
example: '/sdu/ygb/zytz',
parameters: { type: '默认为`zytz`' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '研工部',
maintainers: ['kukeya'],
handler,
description: `| 重要通知 | 管理服务 | 创新实践 |
| -------- | -------- |-------- |
| zytz | glfw | cxsj | `,
};

async function handler(ctx) {
const type = ctx.req.param('type') ?? 'zytz';
const link = new URL(typeMap[type].url, host).href;

const response = await got(link);

const $ = load(response.data);
let item = $('.zytz-list li')
.toArray()
.map((e) => {
e = $(e);
const a = e.find('a');
let link = '';
link = a.attr('href').startsWith('info/') || a.attr('href').startsWith('content') ? host + a.attr('href') : a.attr('href');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let link = '';
link = a.attr('href').startsWith('info/') || a.attr('href').startsWith('content') ? host + a.attr('href') : a.attr('href');
const link = a.attr('href').startsWith('info/') || a.attr('href').startsWith('content') ? host + a.attr('href') : a.attr('href');

return {
title: a.text().trim(),
TonyRL marked this conversation as resolved.
Show resolved Hide resolved
link,
pubDate: parseDate(e.find('b').text().trim().slice(1, -1), 'YYYY-MM-DD'),
};
});

item = await Promise.all(
item.map((item) =>
cache.tryGet(item.link, async () => {
const hostname = new URL(item.link).hostname;
if (hostname === 'mp.weixin.qq.com') {
return finishArticleItem(item);
}
const response = await got(item.link);
const $ = load(response.data);

item.description = $('.v_news_content').html();

return item;
})
)
);

return {
title: `山东大学研工部${typeMap[type].title}`,
description: $('title').text(),
link,
item,
icon: 'https://www.ygb.sdu.edu.cn/img/logo.png',
};
}