Skip to content

Commit

Permalink
feat(route): add 山东大学CS学院研究生工作网站及青岛校区学科建设与研究生教育办公室 (#16811)
Browse files Browse the repository at this point in the history
* feat(route): add 山东大学计算机科学与技术学院研究生工作网站

* feat(route): add 山东大学(青岛)学科建设与研究生教育办公室

* fix: /sdu/cs/yjsgz

* fix: /sdu/qd/xyb
  • Loading branch information
kukeya authored Sep 22, 2024
1 parent 1ff059d commit df586c1
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 0 deletions.
85 changes: 85 additions & 0 deletions lib/routes/sdu/cs/yjsgz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
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://csyh.sdu.edu.cn/';
const typeMap = {
zytz: 'zytz.htm',
gsl: 'gsl.htm',
};
const titleMap = {
zytz: '重要通知',
gsl: '公示栏',
};

export const route: Route = {
path: '/cs/yjsgz/:type?',
categories: ['university'],
example: '/sdu/cs/yjsgz/zytz',
parameters: { type: '默认为`zytz`' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '计算机科学与技术学院研究生工作网站',
maintainers: ['kukeya', 'wiketool'],
handler,
description: `| 重要通知 | 公示栏 |
| -------- | -------- |
| zytz | gsl |`,
};

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

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

const response = await got(link);

const $ = load(response.data);

let item = $('.ss li')
.toArray()
.map((e) => {
e = $(e);
const a = e.find('a');
return {
title: a.text().trim(),
link: a.attr('href').startsWith('info/') ? host + a.attr('href') : a.attr('href'),
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: `山东大学计算机科学与技术学院研究生工作网站${titleMap[type]}`,
description: $('title').text(),
link,
item,
icon: 'https://assets.i-scmp.com/static/img/icons/scmp-icon-256x256.png',
logo: 'https://assets.i-scmp.com/static/img/icons/scmp-icon-256x256.png',
};
}
82 changes: 82 additions & 0 deletions lib/routes/sdu/qd/xyb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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://xyb.qd.sdu.edu.cn/';

const typeMap = {
gztz: {
title: '工作通知',
url: 'gztz.htm',
},
};

export const route: Route = {
path: '/qd/xyb/:type?',
categories: ['university'],
example: '/sdu/qd/xyb/gztz',
parameters: { type: '默认为`gztz`' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '青岛校区学科建设与研究生教育办公室',
maintainers: ['kukeya'],
handler,
description: `| 工作通知 |
| -------- |
| gztz | `,
};

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

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

const response = await got(link);

const $ = load(response.data);

let item = $('.list li')
.toArray()
.map((e) => {
e = $(e);
const a = e.find('a');
return {
title: a.text().slice(1).trim(),
link: a.attr('href').startsWith('info/') ? host + a.attr('href') : a.attr('href'),
pubDate: parseDate(e.find('b').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,
};
}

0 comments on commit df586c1

Please sign in to comment.