diff --git a/lib/routes/scu/namespace.ts b/lib/routes/scu/namespace.ts new file mode 100644 index 00000000000000..75b8db5fdb8e5b --- /dev/null +++ b/lib/routes/scu/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '四川大学', + url: 'www.scu.edu.cn', + lang: 'zh-CN', +}; diff --git a/lib/routes/scu/scupi/_utils.ts b/lib/routes/scu/scupi/_utils.ts new file mode 100644 index 00000000000000..4446cb9a96df95 --- /dev/null +++ b/lib/routes/scu/scupi/_utils.ts @@ -0,0 +1,63 @@ +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { config } from '@/config'; + +export async function getNotifList() { + try { + const response = await got.get('https://scupi.scu.edu.cn/activities/notice', { + headers: { + 'User-Agent': config.ua, + }, + }); + const html = response.body; + const $ = load(html); + + const listElement = $('body > div.wrapper > main > section > div > div > div.news > div > ul'); + return listElement + .find('article') + .toArray() + .map((articleElement) => { + const titleElement = $(articleElement).find('li > div > div.news-text > h4 > a'); + const timeElement = $(articleElement).find('li > div > div.news-text > span'); + const imageElement = $(articleElement).find('li > div > div.news-img > a > img'); + + const link = titleElement.attr('href'); + const title = titleElement.attr('title'); + const pubDate = timeElement.text().trim(); + + return { + title, + link, + itunes_item_image: imageElement.attr('src'), + pubDate: parseDate(pubDate, 'YYYY-MM-DD'), + }; + }); + } catch { + // console.error(error); + } + + return []; +} + +export async function getArticle(item) { + try { + const response = await got.get(item.link, { + headers: { + 'User-Agent': config.ua, + }, + }); + const html = response.body; + const $ = load(html); + const articleContentElement = $('body > div > main > section > div > div > div.post-content-contaier > div'); + const content = articleContentElement.html(); + const modifiedContent = content?.replace(/\n/g, '
'); + + item.description = modifiedContent; + return item; + } catch { + // console.error(error); + } + + return item; +} diff --git a/lib/routes/scu/scupi/notice.ts b/lib/routes/scu/scupi/notice.ts new file mode 100644 index 00000000000000..b7cc03bbd87459 --- /dev/null +++ b/lib/routes/scu/scupi/notice.ts @@ -0,0 +1,40 @@ +// Warning: The author still knows nothing about javascript! + +import { getNotifList, getArticle } from './_utils'; +import { Route } from '@/types'; +import cache from '@/utils/cache'; + +export const route: Route = { + path: '/scupi', + categories: ['university'], + example: '/scu/scupi', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '匹兹堡学院通知', + maintainers: ['sitdownkevin'], + url: 'scupi.scu.edu.cn/activities/notice', + handler, + description: ``, +}; + +async function handler() { + // feed the data to rss + const items = await getNotifList(); + const itemsWithContent = await Promise.all(items.map((item) => cache.tryGet(item.link, () => getArticle(item)))); + + return { + title: '四川大学匹兹堡学院', + description: '四川大学匹兹堡学院官网通知', + language: 'zh-cn', + image: 'https://scupi.scu.edu.cn/wp-content/themes/scupi/img/logo.png', + link: 'https://scupi.scu.edu.cn/', + item: itemsWithContent, + }; +}