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 scu jwc notice #17014

Open
wants to merge 4 commits 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
71 changes: 71 additions & 0 deletions lib/routes/scu/jwc/tzgg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
import { load } from 'cheerio'; // 可以使用类似 jQuery 的 API HTML 解析器

const baseUrl = 'https://jwc.scu.edu.cn/tzgg.htm';
const baseIndexUrl = 'https://jwc.scu.edu.cn/';

export const route: Route = {
path: '/jwc',
categories: ['university'],
example: '/scu/jwc',
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['jwc.scu.edu.cn'],
target: '/jwc',
},
],
name: '教务处通知公告',
maintainers: ['Kyle'],
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
maintainers: ['Kyle'],
maintainers: ['Kyle-You'],

handler,
};

async function handler() {
const { data: response } = await got.get(baseUrl);
const $ = load(response);

const links: string[] = $('.tz-list ul li a')
.toArray()
.map((item) => {
item = $(item);
const link: string = item.attr('href');
return link.startsWith('http') ? link : baseIndexUrl + link;
});

const items = await Promise.all(
links.map((link) =>
cache.tryGet(link, async () => {
const { data: info } = await got.get(link);
const $ = load(info);

// 获取head里的meta标签
const title = $('head meta[name="ArticleTitle"]').attr('content') ?? '';
const pubDate = parseDate($('head meta[name="PubDate"]').attr('content') ?? '');
const description = $('.v_news_content').html();
return {
title,
link,
pubDate,
description,
};
})
)
);

return {
title: '四川大学教务处',
link: baseIndexUrl,
description: '四川大学教务处通知公告',
item: items,
};
}