A Node.js library to get the schedule of the IUT Informatique of Limoges.
- Installation
- Examples
- API
- Credits
Installation
You can install this library via your favorite package manager.
pnpm add edt-iut-info-limoges
yarn add edt-iut-info-limoges
npm install edt-iut-info-limoges --save
TypeScript types are included in this package.
Examples
Get available timetables for a specified year
Here, we'll use year A1
.
import { YEARS, getTimetableEntries } from "edt-iut-info-limoges";
const timetables = await getTimetableEntries(YEARS.A1);
timetables
will be an array of TimetableEntry
objects sorted by their property week_number
.
Get the latest timetable for a specified year and parse it
Here, we'll use year A1
.
import { YEARS, getLatestTimetableEntry } from "edt-iut-info-limoges";
const timetableEntry = await getLatestTimetableEntry(YEARS.A1);
const timetable = await timetableEntry.getTimetable();
Since the timetables are sorted by their week_number
property, the latest timetable will be the last entry of the getTimetableEntries()
array.
timetableEntry
will be a TimetableEntry
object and timetable
will be a Timetable
interface.
Parse a timetable from its buffer
Here, we'll get a timetable entry and get its buffer to later parse it.
You can of course, provide your own buffer, from another source, here it's just to demonstrate.
import { YEARS, getLatestTimetableEntry, getTimetableFromBuffer } from "edt-iut-info-limoges";
const timetableEntry = await getLatestTimetableEntry(YEARS.A1);
const pdfBuffer = await timetableEntry.getBuffer();
const timetable = getTimetableFromBuffer(pdfBuffer);
timetable
will be a Timetable
interface.
Get the lessons for a specified group and subgroup
Here, we'll be G1A
, so group 1
and subgroup A
.
import { getLatestTimetableEntry, YEARS, SUBGROUPS, LESSON_TYPES } from "edt-iut-info-limoges";
const timetableEntry = await getLatestTimetableEntry(YEARS.A1);
const timetable = await timetableEntry.getTimetable();
const lessonsForG1A = timetable.lessons.filter(lesson => {
let isForG1A = false;
switch (lesson.type) {
case LESSON_TYPES.TP:
isForG1A = lesson.group.sub === SUBGROUPS.A && lesson.group.main === 1;
break;
case LESSON_TYPES.TD:
case LESSON_TYPES.DS:
case LESSON_TYPES.SAE:
if (typeof lesson.group === "undefined") {
isForUser = true;
break;
}
else if (lesson.type === LESSON_TYPES.SAE && typeof lesson.group.sub !== "undefined") {
isForUser = lesson.group.main === 1 && lesson.group.sub === SUBGROUPS.A;
break;
}
else {
isForUser = lesson.group.main === 1;
break;
}
case LESSON_TYPES.CM:
case LESSON_TYPES.OTHER:
isForG1A = true;
break;
}
return isForG1A;
});
API
YEARS
An helper enum containing all the available years.
import { YEARS } from "edt-iut-info-limoges";
console.log(YEARS.A1);
console.log(YEARS.A2);
console.log(YEARS.A3);
SUBGROUPS
An helper enum containing all the available subgroups.
In the API, the subgroups are represented by a number while they are represented by a letter in real life. This enum is here to help you convert the letters to numbers.
import { SUBGROUPS } from "edt-iut-info-limoges";
console.log(SUBGROUPS.A);
console.log(SUBGROUPS.B);
LESSON_TYPES
An helper enum containing all the available lesson types.
You can use this enum to filter the lessons using their type
property.
import { LESSON_TYPES } from "edt-iut-info-limoges";
console.log(LESSON_TYPES.CM);
console.log(LESSON_TYPES.TD);
console.log(LESSON_TYPES.TP);
console.log(LESSON_TYPES.DS);
console.log(LESSON_TYPES.SAE);
console.log(LESSON_TYPES.OTHER);
TimetableEntry
A class representing a timetable entry.
interface TimetableEntry {
file_name: string;
last_updated: DateTime;
week_number: number;
from_year: YEARS;
link: string;
getBuffer(): Promise<Buffer>;
getTimetable(): Promise<Timetable>;
lastUpdated(): Promise<DateTime>;
}
Can be obtained using the getTimetableEntries()
and getLatestTimetableEntry()
functions.
Timetable
An interface representing a timetable.
interface Timetable {
header: {
week_number: number;
week_number_in_year: number;
start_date: DateTime;
end_date: DateTime;
}
lessons: TimetableLesson[];
}
TimetableLesson
An interface representing a lesson.
You can use the type
property to filter the lessons using the LESSON_TYPES
enum. Each lesson type has its own properties.
interface TimetableLessonCM {
type: LESSON_TYPES.CM;
content: {
type: string;
raw_lesson: string;
lesson_from_reference?: string;
teacher: string;
room: string;
}
}
interface TimetableLessonTP {
type: LESSON_TYPES.TP;
group: {
main: number;
sub: SUBGROUPS;
}
content: {
type: string;
teacher: string;
room: string;
lesson_from_reference?: string;
}
}
interface TimetableLessonTD {
type: LESSON_TYPES.TD;
group: {
main: number;
}
content: {
type: string;
teacher: string;
room: string;
lesson_from_reference?: string;
}
}
interface TimetableLessonDS {
type: LESSON_TYPES.DS;
group: {
main: number;
}
content: {
type: string;
teacher: string;
room: string;
lesson_from_reference?: string;
}
}
interface TimetableLessonSAE {
type: LESSON_TYPES.SAE;
group: {
main: number;
sub?: SUBGROUPS;
} | undefined
content: {
type: string;
teacher: string;
lesson_from_reference?: string;
raw_lesson?: string;
room: string;
}
}
interface TimetableLessonOTHER {
type: LESSON_TYPES.OTHER;
content: {
description: string;
teacher: string;
room: string;
}
}
type TimetableLesson = {
start_date: DateTime;
end_date: DateTime;
} & (
| TimetableLessonCM
| TimetableLessonTP
| TimetableLessonTD
| TimetableLessonDS
| TimetableLessonSAE
| TimetableLessonOTHER
);
Credits
This project wouldn't have been possible without them.