Skip to content

Commit

Permalink
feat(route): Add /tongji/gs and Update /tongji/yjs (#18174)
Browse files Browse the repository at this point in the history
* Update /tongji/gs and /tongji/yjs

* Replace text() with html()
  • Loading branch information
sitdownkevin authored Jan 22, 2025
1 parent e8c26f2 commit 6b3af0b
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 20 deletions.
66 changes: 66 additions & 0 deletions lib/routes/tongji/gs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import cache from '@/utils/cache';

export const route: Route = {
path: '/gs',
categories: ['university'],
example: '/tongji/gs',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['gs.tongji.edu.cn/tzgg.htm', 'gs.tongji.edu.cn/'],
},
],
name: 'ē ”ē©¶ē”Ÿé™¢é€šēŸ„公告',
maintainers: ['sitdownkevin'],
handler,
url: 'gs.tongji.edu.cn/tzgg.htm',
};

async function getNoticeContent(item) {
const response = await got(item.link);
const $ = load(response.body);
const content = $('#vsb_content').html();
item.description = content;
return item;
}

async function handler() {
const baseUrl = 'https://gs.tongji.edu.cn';
const response = await got(`${baseUrl}/tzgg.htm`);
const $ = load(response.body);
const container = $('body > div > div.con_list.ma0a > div > div.list_content_right > div.list_list > ul');
const items = container
.find('li')
.toArray()
.map((item) => {
const title = $(item).find('a').attr('title');
const linkRaw = $(item).find('a').attr('href');
const link = linkRaw.startsWith('http') ? linkRaw : `${baseUrl}/${linkRaw}`;
const pubDate = $(item).find('span').text();
return { title, link, pubDate: parseDate(pubDate, 'YYYY-MM-DD') };
});

const itemsWithContent = await Promise.all(items.map((item) => cache.tryGet(item.link, () => getNoticeContent(item))));

return {
title: 'åŒęµŽå¤§å­¦ē ”ē©¶ē”Ÿé™¢',
link: baseUrl,
description: 'åŒęµŽå¤§å­¦ē ”ē©¶ē”Ÿé™¢é€šēŸ„公告',
image: 'https://upload.wikimedia.org/wikipedia/zh/f/f8/Tongji_University_Emblem.svg',
icon: 'https://upload.wikimedia.org/wikipedia/zh/f/f8/Tongji_University_Emblem.svg',
logo: 'https://upload.wikimedia.org/wikipedia/zh/f/f8/Tongji_University_Emblem.svg',
item: itemsWithContent,
};
}
54 changes: 34 additions & 20 deletions lib/routes/tongji/yjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import cache from '@/utils/cache';

export const route: Route = {
path: '/yjs',
Expand All @@ -21,32 +22,45 @@ export const route: Route = {
source: ['yz.tongji.edu.cn/zsxw/ggtz.htm', 'yz.tongji.edu.cn/'],
},
],
name: 'ē ”ē©¶ē”Ÿé™¢é€šēŸ„公告',
maintainers: ['shengmaosu'],
name: 'ē ”ē©¶ē”Ÿę‹›ē”Ÿē½‘通ēŸ„公告',
maintainers: ['shengmaosu', 'sitdownkevin'],
handler,
url: 'yz.tongji.edu.cn/zsxw/ggtz.htm',
};

async function handler() {
const link = 'https://yz.tongji.edu.cn/zsxw/ggtz.htm';
const response = await got(link);
async function getNoticeContent(item) {
const response = await got(item.link);
const $ = load(response.data);
const list = $('.list_main_content li');
const content = $('#vsb_content').html();
item.description = content;
return item;
}

async function handler() {
const baseUrl = 'https://yz.tongji.edu.cn';
const response = await got(`${baseUrl}/zsxw/ggtz.htm`);
const $ = load(response.body);
const container = $('#content-box > div.content > div.list_main_content > ul');
const items = container
.find('li')
.toArray()
.map((item) => {
const title = $(item).find('a').attr('title');
const linkRaw = $(item).find('a').attr('href');
const link = linkRaw.startsWith('http') ? linkRaw : new URL(linkRaw, `${baseUrl}/zsxw`).toString();
const pubDate = $(item).find('span').text();
return { title, link, pubDate: parseDate(pubDate, 'YYYY-MM-DD') };
});

const itemsWithContent = await Promise.all(items.map((item) => cache.tryGet(item.link, () => getNoticeContent(item))));

return {
title: 'åŒęµŽå¤§å­¦ē ”ē©¶ē”Ÿé™¢',
link,
description: 'åŒęµŽå¤§å­¦ē ”ē©¶ē”Ÿé™¢é€šēŸ„公告',
item:
list &&
list.toArray().map((item) => {
item = $(item);
const a = item.find('a');
return {
title: a.attr('title'),
link: new URL(a.attr('href'), link).href,
pubDate: parseDate(item.find('span').text(), 'YYYY-MM-DD'),
};
}),
title: 'åŒęµŽå¤§å­¦ē ”ē©¶ē”Ÿę‹›ē”Ÿē½‘',
link: baseUrl,
description: 'åŒęµŽå¤§å­¦ē ”ē©¶ē”Ÿę‹›ē”Ÿē½‘通ēŸ„公告',
image: 'https://upload.wikimedia.org/wikipedia/zh/f/f8/Tongji_University_Emblem.svg',
icon: 'https://upload.wikimedia.org/wikipedia/zh/f/f8/Tongji_University_Emblem.svg',
logo: 'https://upload.wikimedia.org/wikipedia/zh/f/f8/Tongji_University_Emblem.svg',
item: itemsWithContent,
};
}

0 comments on commit 6b3af0b

Please sign in to comment.