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): 新增 华南理工大学校团委通知公告 路由 #17148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
63 changes: 63 additions & 0 deletions lib/routes/scut/young/notice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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 ofetch from '@/utils/ofetch';
Comment on lines +3 to +6
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use either ofetch or got but not both.


export const route: Route = {
path: '/young/notice',
categories: ['university'],
example: '/scut/young/notice',
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '校团委 - 通知公告',
maintainers: ['gdzhht'],
handler,
description: `:::warning
由于学校网站对非大陆 IP 的访问存在限制,可能需自行部署。
:::`,
};

async function handler() {
const baseUrl = 'https://www2.scut.edu.cn';
const url = 'https://www2.scut.edu.cn/youth/tzgg/list.htm';

const { data: response } = await got(url);
const $ = load(response);

const list = $('#wp_news_w3 ul li')
.toArray()
.map((item) => {
item = $(item);
const a = item.find('li a');
return {
title: item.find('li a .title span').text(),
link: a.attr('href')?.startsWith('http') ? a.attr('href') : `${baseUrl}${a.attr('href')}`,
pubDate: parseDate(item.find('li a .date').text(), 'YYYY-MM-DD'),
};
});

const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const response = await ofetch(item.link);
const $ = load(response);
item.description = $('div.wp_articlecontent').html();
return item;
})
)
);

return {
title: '共青团华南理工大学委员会 - 通知公告',
link: url,
item: items,
};
}