-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add 山青学生在线、山大研工部、山大国际网站 (#16812)
* feat(route): add 山大国际网站 * feat(route): add 山东大学研工部网站 * feat(route): add 山东大学(青岛)学生在线 * fix: /sdu/gjsw * fix: /sdu/qd/xszxqd * fix: /sdu/ygb * fix: /sdu/gjsw description * fix: /sdu/qd/xszxqd link * fix: /sdu/ygb link
- Loading branch information
Showing
3 changed files
with
268 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { Route } from '@/types'; | ||
import cache from '@/utils/cache'; | ||
import got from '@/utils/got'; | ||
import { load } from 'cheerio'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import { finishArticleItem } from '@/utils/wechat-mp'; | ||
|
||
const host = 'https://www.ipo.sdu.edu.cn/'; | ||
|
||
const typeMap = { | ||
tzgg: { | ||
title: '通知公告', | ||
url: 'tzgg.htm', | ||
}, | ||
}; | ||
|
||
export const route: Route = { | ||
path: '/gjsw/:type?', | ||
categories: ['university'], | ||
example: '/sdu/gjsw/tzgg', | ||
parameters: { type: '默认为`tzgg`' }, | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
name: '国际事务部', | ||
maintainers: ['kukeya'], | ||
handler, | ||
description: `| 通知公告 | | ||
| -------- | | ||
| tzgg | `, | ||
}; | ||
|
||
async function handler(ctx) { | ||
const type = ctx.req.param('type') ?? 'tzgg'; | ||
|
||
const link = new URL(typeMap[type].url, host).href; | ||
const response = await got(link); | ||
|
||
const $ = load(response.data); | ||
|
||
let item = $('.dqlb ul li') | ||
.toArray() | ||
.map((e) => { | ||
e = $(e); | ||
const a = e.find('a'); | ||
return { | ||
title: a.text().trim(), | ||
link: a.attr('href').startsWith('wdhcontent') ? host + a.attr('href') : a.attr('href'), | ||
pubDate: parseDate(e.find('.fr').text().trim(), 'YYYY-MM-DD'), | ||
}; | ||
}); | ||
|
||
item = await Promise.all( | ||
item.map((item) => | ||
cache.tryGet(item.link, async () => { | ||
const hostname = new URL(item.link).hostname; | ||
if (hostname === 'mp.weixin.qq.com') { | ||
return finishArticleItem(item); | ||
} | ||
const response = await got(item.link); | ||
const $ = load(response.data); | ||
item.description = $('.v_news_content').html(); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
return { | ||
title: `山东大学国际事务部${typeMap[type].title}`, | ||
description: $('title').text(), | ||
link, | ||
item, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { Route } from '@/types'; | ||
import cache from '@/utils/cache'; | ||
import got from '@/utils/got'; | ||
import { load } from 'cheerio'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import { finishArticleItem } from '@/utils/wechat-mp'; | ||
|
||
const host = 'https://www.onlineqd.sdu.edu.cn/'; | ||
|
||
const typeMap = { | ||
'xttz-yjs': { | ||
title: '学团通知-研究生', | ||
url: 'list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1027', | ||
}, | ||
'xttz-bks': { | ||
title: '学团通知-本科生', | ||
url: 'list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1025', | ||
}, | ||
'xttz-tx': { | ||
title: '学团通知-团学', | ||
url: 'list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1026', | ||
}, | ||
'xttz-xl': { | ||
title: '学团通知-心理', | ||
url: 'list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1029', | ||
}, | ||
xtyw: { | ||
title: '学团要闻', | ||
url: 'list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1008', | ||
}, | ||
}; | ||
|
||
export const route: Route = { | ||
path: '/qd/xszxqd/:type?', | ||
categories: ['university'], | ||
example: '/sdu/qd/xszxqd/xtyw', | ||
parameters: { type: '默认为`xtyw`' }, | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
name: '学生在线(青岛)', | ||
maintainers: ['kukeya'], | ||
handler, | ||
description: `| 学团通知-研究生 | 学团通知-本科生 | 学团通知-团学 | 学团通知-心理 | 学团要闻 | ||
| -------- | -------- |-------- |-------- |-------- | | ||
| xttz-yjs | xttz-bks | xttz-tx | xttz-xl | xtyw |`, | ||
}; | ||
|
||
async function handler(ctx) { | ||
const type = ctx.req.param('type') ?? 'xtyw'; | ||
const link = new URL(typeMap[type].url, host).href; | ||
|
||
const response = await got(link); | ||
|
||
const $ = load(response.data); | ||
|
||
let item = $('.list_box li') | ||
.toArray() | ||
.map((e) => { | ||
e = $(e); | ||
const a = e.find('a'); | ||
const link = a.attr('href').startsWith('tz_content') || a.attr('href').startsWith('content') ? host + a.attr('href') : a.attr('href'); | ||
return { | ||
title: a.text().trim(), | ||
link, | ||
pubDate: parseDate(e.find('span').text().trim(), 'YYYY-MM-DD'), | ||
}; | ||
}); | ||
|
||
item = await Promise.all( | ||
item.map((item) => | ||
cache.tryGet(item.link, async () => { | ||
const hostname = new URL(item.link).hostname; | ||
if (hostname === 'mp.weixin.qq.com') { | ||
return finishArticleItem(item); | ||
} | ||
const response = await got(item.link); | ||
const $ = load(response.data); | ||
item.description = $('.v_news_content').html(); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
return { | ||
title: `山东大学学生在线(青岛)${typeMap[type].title}`, | ||
description: $('title').text(), | ||
link, | ||
item, | ||
icon: 'https://www.onlineqd.sdu.edu.cn/img/logo.png', | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { Route } from '@/types'; | ||
import cache from '@/utils/cache'; | ||
import got from '@/utils/got'; | ||
import { load } from 'cheerio'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import { finishArticleItem } from '@/utils/wechat-mp'; | ||
|
||
const host = 'https://www.ygb.sdu.edu.cn/'; | ||
|
||
const typeMap = { | ||
zytz: { | ||
title: '重要通知', | ||
url: 'zytz.htm', | ||
}, | ||
glfw: { | ||
title: '管理服务', | ||
url: 'glfw.htm', | ||
}, | ||
cxsj: { | ||
title: '创新实践', | ||
url: 'cxsj.htm', | ||
}, | ||
}; | ||
|
||
export const route: Route = { | ||
path: '/ygb/:type?', | ||
categories: ['university'], | ||
example: '/sdu/ygb/zytz', | ||
parameters: { type: '默认为`zytz`' }, | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
name: '研工部', | ||
maintainers: ['kukeya'], | ||
handler, | ||
description: `| 重要通知 | 管理服务 | 创新实践 | | ||
| -------- | -------- |-------- | | ||
| zytz | glfw | cxsj | `, | ||
}; | ||
|
||
async function handler(ctx) { | ||
const type = ctx.req.param('type') ?? 'zytz'; | ||
const link = new URL(typeMap[type].url, host).href; | ||
|
||
const response = await got(link); | ||
|
||
const $ = load(response.data); | ||
let item = $('.zytz-list li') | ||
.toArray() | ||
.map((e) => { | ||
e = $(e); | ||
const a = e.find('a'); | ||
const link = a.attr('href').startsWith('info/') || a.attr('href').startsWith('content') ? host + a.attr('href') : a.attr('href'); | ||
return { | ||
title: a.text().trim(), | ||
link, | ||
pubDate: parseDate(e.find('b').text().trim().slice(1, -1), 'YYYY-MM-DD'), | ||
}; | ||
}); | ||
|
||
item = await Promise.all( | ||
item.map((item) => | ||
cache.tryGet(item.link, async () => { | ||
const hostname = new URL(item.link).hostname; | ||
if (hostname === 'mp.weixin.qq.com') { | ||
return finishArticleItem(item); | ||
} | ||
const response = await got(item.link); | ||
const $ = load(response.data); | ||
|
||
item.description = $('.v_news_content').html(); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
return { | ||
title: `山东大学研工部${typeMap[type].title}`, | ||
description: $('title').text(), | ||
link, | ||
item, | ||
icon: 'https://www.ygb.sdu.edu.cn/img/logo.png', | ||
}; | ||
} |