Skip to content

Commit

Permalink
feat: add route for School of Economics & Management, Tongji Universi…
Browse files Browse the repository at this point in the history
…ty (同济大学经济与管理学院) (DIYgod#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
  • Loading branch information
sitdownkevin authored Nov 10, 2024
1 parent 468bfcd commit 6895333
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/routes/tongji/sem/_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import { config } from '@/config';

export async function getNotifByPage() {
const pageUrl: string = `https://sem.tongji.edu.cn/semch/category/frontpage/notice`;

try {
const response = await got.get(pageUrl, {
headers: {
'User-Agent': config.ua,
},
});

const html = response.body;
const $ = load(html);

const notifListElements = $('#page-wrap > div.maim_pages > div > div.leftmain_page > div > ul > li');

return notifListElements.toArray().map((Element) => {
const aTagFirst = $(Element).find('a.bt');
const aTagSecond = $(Element).find('a.time');

const title = aTagFirst.attr('title');
const href = aTagFirst.attr('href');
const time = aTagSecond.text().trim();

return {
title,
link: href,
pubDate: parseDate(time, 'YYYY-MM-DD'),
};
});
} catch {
// console.error(error);
}
return [];
}
34 changes: 34 additions & 0 deletions lib/routes/tongji/sem/notice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Warning: The author still knows nothing about javascript!
import { Route } from '@/types';
import { getNotifByPage } from './_utils';

export const route: Route = {
path: '/sem',
categories: ['university'],
example: '/tongji/sem',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '经济与管理学院通知',
maintainers: ['sitdownkevin'],
url: 'sem.tongji.edu.cn/semch/category/frontpage/notice',
handler,
description: ``,
};

async function handler() {
const results = await getNotifByPage();

// feed the data to rss
return {
title: '同济大学经济与管理学院',
link: 'https://sem.tongji.edu.cn/semch/category/frontpage/notice',
item: results,
};
}

0 comments on commit 6895333

Please sign in to comment.