-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
42 lines (35 loc) · 1.22 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { getCoursesForTerm, searchPost } from "/banner/course.ts";
import { getAllSubjects } from "/banner/subject.ts";
import { getTerms } from "/banner/term.ts";
import { Course } from "@/types.ts";
import { transformCourse } from "/transformers/course.ts";
import { writeJSON } from "/util/file.ts";
const { cookie } = await getTerms({ noTerms: 1 });
// await writeJSON("./data/terms.json", terms);
// console.log("Found terms");
// Only use Fall 2022
const fallTerm = {
code: "202310",
description: "Fall 2022 Semester",
};
const subjects = await getAllSubjects([fallTerm]);
await writeJSON("./data/subjects.json", subjects);
console.log("Found subjects");
// Create the object
const fetchedCourses: Record<string, Course[]> = {};
subjects.forEach((subject) => (fetchedCourses[subject.code] = []));
for await (const subject of subjects) {
console.log(`Starting ${subject.code}`);
await searchPost(cookie, fallTerm.code);
const coursesForTerm = await getCoursesForTerm(
cookie,
fallTerm.code,
subject.code,
);
// fetchedCourses[subject.code].push(...coursesForTerm);
writeJSON(
`./data/courses/${subject.code}.json`,
coursesForTerm.map(transformCourse),
);
console.log(`Finished ${subject.code}`);
}