Skip to content

Commit

Permalink
feat(route): add scu jwc notice (#17014)
Browse files Browse the repository at this point in the history
* 添加SCU教务处通知公告路由

* 空提交

* feat(route): cache tzgg

* Update lib/routes/scu/jwc/tzgg.ts
  • Loading branch information
Kyle-You authored Nov 17, 2024
1 parent b05cb70 commit 97cdb21
Showing 1 changed file with 71 additions and 0 deletions.
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-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,
};
}

0 comments on commit 97cdb21

Please sign in to comment.