Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"dependencies": {
"@elysiajs/cors": "^1.3.3",
"@elysiajs/node": "^1.3.0",
"@types/luxon": "^3.7.1",
"axios": "^1.10.0",
"cheerio": "^1.0.0-rc.12",
"elysia": "^1.3.5",
"luxon": "^3.7.1",
"pg": "^8.16.3",
"zod": "^3.25.67",
},
Expand Down Expand Up @@ -430,6 +432,8 @@

"@types/jest": ["@types/[email protected]", "", { "dependencies": { "expect": "^29.0.0", "pretty-format": "^29.0.0" } }, "sha512-ZN+4sdnLUbo8EVvVc2ao0GFW6oVrQRPn4K2lglySj7APvSrgzxHiNNK99us4WDMi57xxA2yggblIAMNhXOotLQ=="],

"@types/luxon": ["@types/[email protected]", "", {}, "sha512-H3iskjFIAn5SlJU7OuxUmTEpebK6TKB8rxZShDslBMZJ5u9S//KM1sbdAisiSrqwLQncVjnpi2OK2J51h+4lsg=="],

"@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~7.8.0" } }, "sha512-4zXMWD91vBLGRtHK3YbIoFMia+1nqEz72coM42C5ETjnNCa/heoj7NT1G67iAfOqMmcfhuCZ4uNpyz8EjlAejw=="],

"@types/pg": ["@types/[email protected]", "", { "dependencies": { "@types/node": "*", "pg-protocol": "*", "pg-types": "^2.2.0" } }, "sha512-I6UNVBAoYbvuWkkU3oosC8yxqH21f4/Jc4DK71JLG3dT2mdlGe1z+ep/LQGXaKaOgcvUrsQoPRqfgtMcvZiJhg=="],
Expand Down Expand Up @@ -768,6 +772,8 @@

"lru-cache": ["[email protected]", "", { "dependencies": { "yallist": "^3.0.2" } }, "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w=="],

"luxon": ["[email protected]", "", {}, "sha512-RkRWjA926cTvz5rAb1BqyWkKbbjzCGchDUIKMCUvNi17j6f6j8uHGDV82Aqcqtzd+icoYpELmG3ksgGiFNNcNg=="],

"make-dir": ["[email protected]", "", { "dependencies": { "semver": "^7.5.3" } }, "sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw=="],

"make-error": ["[email protected]", "", {}, "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw=="],
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
"dependencies": {
"@elysiajs/cors": "^1.3.3",
"@elysiajs/node": "^1.3.0",
"@types/luxon": "^3.7.1",
"axios": "^1.10.0",
"cheerio": "^1.0.0-rc.12",
"elysia": "^1.3.5",
"luxon": "^3.7.1",
"pg": "^8.16.3",
"zod": "^3.25.67"
},
Expand Down
16 changes: 9 additions & 7 deletions src/containers/locationBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { getHTMLResponse } from "utils/requestUtils";
import { load } from "cheerio";
import type { Element } from "domhandler";
import { getTimeRangesFromString } from "./timeBuilder";
import { getAllTimeSlotsFromSchedule } from "./timeBuilder";
import {
ICoordinate,
ILocation,
ILocationCoordinateOverwrites,
ISpecial,
ITimeRange,
} from "../types";
import { sortAndMergeTimeRanges } from "utils/timeUtils";
import { ITimeOverwrites } from "overwrites/timeOverwrites";

/**
* For building the location data structure
Expand Down Expand Up @@ -77,11 +77,12 @@ export default class LocationBuilder {
return { lat: parseFloat(latitude), lng: parseFloat(longitude) };
}

async populateDetailedInfo() {
async populateDetailedInfo(timeSlotOverwrites: ITimeOverwrites = {}) {
const conceptURL = this.getConceptLink();
if (!conceptURL) return;

const $ = load(await getHTMLResponse(conceptURL));
const { body, serverDate } = await getHTMLResponse(conceptURL);
const $ = load(body);
this.url = conceptURL.toString();
this.description = $("div.description p").text().trim();
this.menu = $("div.navItems > a#getMenu").attr("href");
Expand All @@ -95,8 +96,10 @@ export default class LocationBuilder {
}

const nextSevenDays = $("ul.schedule").find("li").toArray();
this.times = sortAndMergeTimeRanges(
nextSevenDays.flatMap((rowHTML) => getTimeRangesFromString(rowHTML))
this.times = getAllTimeSlotsFromSchedule(
nextSevenDays,
serverDate.year,
timeSlotOverwrites
);
}
getConceptLink() {
Expand All @@ -105,7 +108,6 @@ export default class LocationBuilder {
}

getConceptId() {
if (this.conceptId === undefined) return undefined;
return this.conceptId;
}

Expand Down
7 changes: 7 additions & 0 deletions src/containers/time/parsedTimeForDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { MonthOfTheYear } from "types";
import ParsedTimeBase from "./parsedTimeBase";

export interface IParsedTimeDate {
/** 1-12 */
month: MonthOfTheYear;
/* 1-31 */
date: number;
}

Expand Down Expand Up @@ -36,6 +38,11 @@ export default class ParsedTimeForDate extends ParsedTimeBase {
}
}

/**
* Throws error when failed
* @param monthStr
* @returns
*/
export function convertMonthStringToEnum(monthStr: string): MonthOfTheYear {
const normalizedMonth = monthStr.trim().toLowerCase();
switch (normalizedMonth) {
Expand Down
21 changes: 10 additions & 11 deletions src/containers/time/parsedTimeForDay.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
import { DayOfTheWeek } from "types";
import ParsedTimeBase from "./parsedTimeBase";

/**
* For parsing a string representing a day to a day of the week enum
* For parsing a string representing a day to a day of the week (0-6)
*/
export default class ParsedTimeForDay extends ParsedTimeBase {
declare value: DayOfTheWeek;
declare value: number;

parse() {
this.value = convertDayStringToEnum(this.input);
return this;
}
}

export function convertDayStringToEnum(dayStr: string): DayOfTheWeek {
export function convertDayStringToEnum(dayStr: string): number {
const normalizedDay = dayStr.trim().toLowerCase();
switch (normalizedDay) {
case "sunday":
case "sun":
return DayOfTheWeek.SUNDAY;
return 0;
case "monday":
case "mon":
return DayOfTheWeek.MONDAY;
return 1;
case "tuesday":
case "tue":
return DayOfTheWeek.TUESDAY;
return 2;
case "wednesday":
case "wed":
return DayOfTheWeek.WEDNESDAY;
return 3;
case "thursday":
case "thu":
case "thurs":
return DayOfTheWeek.THURSDAY;
return 4;
case "friday":
case "fri":
return DayOfTheWeek.FRIDAY;
return 5;
case "saturday":
case "sat":
return DayOfTheWeek.SATURDAY;
return 6;
default:
throw new Error(`Invalid Day: ${dayStr}`);
}
Expand Down
Loading