diff --git a/lib/routes/tongji/sem/_utils.ts b/lib/routes/tongji/sem/_utils.ts new file mode 100644 index 00000000000000..2a45f9c2ce628a --- /dev/null +++ b/lib/routes/tongji/sem/_utils.ts @@ -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 []; +} diff --git a/lib/routes/tongji/sem/notice.ts b/lib/routes/tongji/sem/notice.ts new file mode 100644 index 00000000000000..55651dad99c78f --- /dev/null +++ b/lib/routes/tongji/sem/notice.ts @@ -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, + }; +}