Add dates, discipline fallbacks
This commit is contained in:
@@ -6,15 +6,15 @@ import { JSDOM } from 'jsdom'
|
||||
import { content as mockContent } from './mock'
|
||||
|
||||
// ПС-7: 146
|
||||
export async function getSchedule(groupID: number): Promise<Day[]> {
|
||||
// const page = await fetch(`${process.env.PROXY_URL ?? 'https://lk.ks.psuti.ru'}/?mn=2&obj=${groupID}`)
|
||||
const page = { text: async () => mockContent, status: 200, headers: { get: (s: string) => s && 'text/html' } }
|
||||
export async function getSchedule(groupID: number, groupName: string): Promise<Day[]> {
|
||||
const page = await fetch(`${process.env.PROXY_URL ?? 'https://lk.ks.psuti.ru'}/?mn=2&obj=${groupID}`)
|
||||
// const page = { text: async () => mockContent, status: 200, headers: { get: (s: string) => s && 'text/html' } }
|
||||
const content = await page.text()
|
||||
const contentType = page.headers.get('content-type')
|
||||
if (page.status === 200 && contentType && contentTypeParser.parse(contentType).type === 'text/html') {
|
||||
try {
|
||||
const root = new JSDOM(content).window.document
|
||||
return parsePage(root)
|
||||
return parsePage(root, groupName)
|
||||
} catch(e) {
|
||||
console.error('Error while parsing lk.ks.psuti.ru')
|
||||
throw e
|
||||
|
||||
Reference in New Issue
Block a user