CourseScraper completely done
'
This commit is contained in:
@@ -18,12 +18,6 @@ export type Instructor = {
|
||||
*/
|
||||
export type InstructionMode = 'Online' | 'In Person' | 'Hybrid';
|
||||
|
||||
export type Links = {
|
||||
syllabi?: string;
|
||||
textbook?: string;
|
||||
eCIS?: string;
|
||||
};
|
||||
|
||||
export enum Status {
|
||||
OPEN = 'OPEN',
|
||||
CLOSED = 'CLOSED',
|
||||
@@ -34,16 +28,15 @@ export enum Status {
|
||||
export class Course {
|
||||
uniqueId: number;
|
||||
number: string;
|
||||
name: string;
|
||||
fullName: string;
|
||||
courseName: string;
|
||||
department: string;
|
||||
status: Status;
|
||||
instructors: Instructor[];
|
||||
isReserved: boolean;
|
||||
description: string[];
|
||||
description?: string[];
|
||||
schedule: CourseSchedule;
|
||||
currentStatus: string;
|
||||
url: string;
|
||||
links: Links;
|
||||
registerURL?: string;
|
||||
flags: string[];
|
||||
instructionMode: InstructionMode;
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
import { Serialized } from 'chrome-extension-toolkit';
|
||||
|
||||
type Day = 'M' | 'T' | 'W' | 'TH' | 'F' | 'S' | 'SU';
|
||||
const dayMap = {
|
||||
M: 'Monday',
|
||||
T: 'Tuesday',
|
||||
W: 'Wednesday',
|
||||
TH: 'Thursday',
|
||||
F: 'Friday',
|
||||
S: 'Saturday',
|
||||
SU: 'Sunday',
|
||||
} as const;
|
||||
|
||||
type Day = typeof dayMap[keyof typeof dayMap];
|
||||
|
||||
type Room = {
|
||||
building: string;
|
||||
number: string;
|
||||
};
|
||||
|
||||
type CourseSection = {
|
||||
export type CourseSection = {
|
||||
day: Day;
|
||||
startTime: number;
|
||||
endTime: number;
|
||||
@@ -21,9 +31,49 @@ export class CourseSchedule {
|
||||
Object.assign(this, courseSchedule);
|
||||
}
|
||||
|
||||
static parse(days: Day[] , times, hours): CourseSchedule {}
|
||||
static parse(dayLine: string, timeLine: string, roomLine: string): CourseSection[] {
|
||||
try {
|
||||
let days: Day[] = dayLine
|
||||
.split('')
|
||||
.map((char, i) => {
|
||||
const nextChar = dayLine.charAt(i + 1);
|
||||
let day = char;
|
||||
if (char === 'T' && nextChar === 'H') {
|
||||
day += nextChar;
|
||||
}
|
||||
if (char === 'S' && nextChar === 'U') {
|
||||
day += nextChar;
|
||||
}
|
||||
return dayMap[day];
|
||||
})
|
||||
.filter(Boolean) as Day[];
|
||||
|
||||
toString(): string {
|
||||
return '';
|
||||
const [startTime, endTime] = timeLine
|
||||
.replaceAll('.', '')
|
||||
.split('-')
|
||||
.map(time => {
|
||||
const [hour, rest] = time.split(':');
|
||||
const [minute, ampm] = rest.split(' ');
|
||||
|
||||
if (ampm === 'pm') {
|
||||
return Number(hour) * 60 + Number(minute) + 12 * 60;
|
||||
}
|
||||
return Number(hour) * 60 + Number(minute);
|
||||
});
|
||||
|
||||
const [building, number] = roomLine.split(' ');
|
||||
|
||||
return days.map(day => ({
|
||||
day,
|
||||
startTime,
|
||||
endTime,
|
||||
room: {
|
||||
building,
|
||||
number,
|
||||
},
|
||||
}));
|
||||
} catch (e) {
|
||||
throw new Error(`Failed to parse schedule: ${dayLine} ${timeLine} ${roomLine}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user