Skip to content

Commit 6895333

Browse files
authored
feat: add route for School of Economics & Management, Tongji University (同济大学经济与管理学院) (#17516)
* Add RSS for Tongji SEM * Update notice.ts * Update _utils.ts * Update notice.ts Fix url * Update notice.ts Fetch data from the first page only. * Update notice.ts * Use the redirected URL instead * Update code
1 parent 468bfcd commit 6895333

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

lib/routes/tongji/sem/_utils.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import got from '@/utils/got';
2+
import { load } from 'cheerio';
3+
import { parseDate } from '@/utils/parse-date';
4+
import { config } from '@/config';
5+
6+
export async function getNotifByPage() {
7+
const pageUrl: string = `https://sem.tongji.edu.cn/semch/category/frontpage/notice`;
8+
9+
try {
10+
const response = await got.get(pageUrl, {
11+
headers: {
12+
'User-Agent': config.ua,
13+
},
14+
});
15+
16+
const html = response.body;
17+
const $ = load(html);
18+
19+
const notifListElements = $('#page-wrap > div.maim_pages > div > div.leftmain_page > div > ul > li');
20+
21+
return notifListElements.toArray().map((Element) => {
22+
const aTagFirst = $(Element).find('a.bt');
23+
const aTagSecond = $(Element).find('a.time');
24+
25+
const title = aTagFirst.attr('title');
26+
const href = aTagFirst.attr('href');
27+
const time = aTagSecond.text().trim();
28+
29+
return {
30+
title,
31+
link: href,
32+
pubDate: parseDate(time, 'YYYY-MM-DD'),
33+
};
34+
});
35+
} catch {
36+
// console.error(error);
37+
}
38+
return [];
39+
}

lib/routes/tongji/sem/notice.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Warning: The author still knows nothing about javascript!
2+
import { Route } from '@/types';
3+
import { getNotifByPage } from './_utils';
4+
5+
export const route: Route = {
6+
path: '/sem',
7+
categories: ['university'],
8+
example: '/tongji/sem',
9+
parameters: {},
10+
features: {
11+
requireConfig: false,
12+
requirePuppeteer: false,
13+
antiCrawler: false,
14+
supportBT: false,
15+
supportPodcast: false,
16+
supportScihub: false,
17+
},
18+
name: '经济与管理学院通知',
19+
maintainers: ['sitdownkevin'],
20+
url: 'sem.tongji.edu.cn/semch/category/frontpage/notice',
21+
handler,
22+
description: ``,
23+
};
24+
25+
async function handler() {
26+
const results = await getNotifByPage();
27+
28+
// feed the data to rss
29+
return {
30+
title: '同济大学经济与管理学院',
31+
link: 'https://sem.tongji.edu.cn/semch/category/frontpage/notice',
32+
item: results,
33+
};
34+
}

0 commit comments

Comments
 (0)