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
74 changes: 60 additions & 14 deletions backend/app/scrap-registrations/scrap_registrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,68 @@ export async function scrapCourseNameGroupsUrls(
.eq(1)
.text()
.trim();
const groups = $("div#layout-c22").find("div.usos-ui").children("usos-frame");
groups.each((_, element) => {
const title = $(element).find("h2");
if (
title.text().includes("(jeszcze nie rozpoczęty)") ||
title.text().includes("(w trakcie)")
) {
const linksToSubCourses = $(element).find("usos-link").children("a");
linksToSubCourses.each((__, el) => {
const url = $(el).attr("href");
if (url !== undefined) {
urls.push(url);
const cycle = $("div#layout-c22")
.find("div.usos-ui")
.children("usos-frame.zajecia")
.filter((_, element) => {
const title = $(element).find("h2");
return (
title.text().includes("(jeszcze nie rozpoczęty)") ||
title.text().includes("(w trakcie)")
);
})
.first();
if (cycle.length > 0) {
// const linksToSubCourses = $(cycle).find("usos-link").children("a");
// linksToSubCourses.each((__, el) => {
// const url = $(el).attr("href");
// if (url !== undefined) {
// urls.push(url);
// }
// });

// they broke the group display in the course view - workaround
const linkToCalendar = $(cycle)
.find("usos-timetable")
.closest("a")
.attr("href");

if (linkToCalendar !== undefined) {
const calendarResponse = await fetchData(linkToCalendar);
if (!calendarResponse.ok) {
throw new Error(
`Got response code ${calendarResponse.status} ${calendarResponse.statusText} while fetching course calendar`,
);
}

const $$ = cheerio.load(await calendarResponse.text());

const courseIds = new Set<string>();
const links = $$("usos-timetable span[slot=dialog-info] a");
for (const link of links) {
const href = $$(link).attr("href");
if (href === undefined) {
continue;
}
});
const courseId = new URL(href).searchParams.get("zaj_cyk_id");
if (courseId === null) {
continue;
}
courseIds.add(courseId);
}

const baseUrl = new URL(courseUrl);
baseUrl.search = "";
baseUrl.searchParams.set(
"_action",
"katalog2/przedmioty/pokazGrupyZajec",
);
for (const id of courseIds) {
baseUrl.searchParams.set("zaj_cyk_id", id);
urls.push(baseUrl.href);
}
}
});
}
return { courseName, urls, courseCode };
}

Expand Down
7 changes: 5 additions & 2 deletions backend/commands/scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,9 @@ export default class Scraper extends BaseCommand {
this.scrapingSemaphore = new Semaphore(this.maxUsosRequests);
this.dbSemaphore = new Semaphore(this.maxDbRequests);

await this.ui
.tasks({ verbose: true })
const tasks = this.ui.tasks({ verbose: true });

await tasks
.add("Scrape departments", async (task) => {
await this.departmentScrapeTask(task);
return "Done";
Expand Down Expand Up @@ -534,5 +535,7 @@ export default class Scraper extends BaseCommand {
return "Done";
})
.run();

this.exitCode = tasks.getState() === "succeeded" ? 0 : 1;
}
}