diff --git a/examples/holidays.ts b/examples/holidays.ts new file mode 100644 index 0000000..7533d74 --- /dev/null +++ b/examples/holidays.ts @@ -0,0 +1,17 @@ +import { authenticatePronoteCredentials, PronoteApiAccountId } from "../src"; + +(async () => { + const pronote = await authenticatePronoteCredentials("https://pronote-vm.dev/pronote", { + accountTypeID: PronoteApiAccountId.Student, + username: "lisa.boulanger", // using my VM credentials here because the demo instance doesn't have any messages. + password: "12345678", + + // Because this is just an example, don't forget to change this. + deviceUUID: "my-device-uuid" + }); + + for (const holiday of pronote.holidays) { + console.info("=>", holiday.name); + console.info("Starts", holiday.start.toLocaleDateString(), "until", holiday.end.toLocaleDateString()); + } +})(); diff --git a/src/client/Pronote.ts b/src/client/Pronote.ts index 83987e7..b02195a 100644 --- a/src/client/Pronote.ts +++ b/src/client/Pronote.ts @@ -47,6 +47,7 @@ import { PronoteApiAttendanceItemType } from "~/constants/attendance"; import { StudentAbsence, StudentDelay, StudentPunishment } from "~/parser/attendance"; import { callApiUserMessageRecipients } from "~/api/user/messageRecipients"; import { FetchedMessageRecipient } from "~/parser/recipient"; +import { Holiday } from ".."; export default class Pronote { /** @@ -117,12 +118,14 @@ export default class Pronote { /** An absolute URL giving the profile picture of the logged in student, if exists. */ public studentProfilePictureURL?: string; - public periods: Array; + public periods: Period[]; private periodsByOnglet: Map; public isDelegate: boolean; public isMemberCA: boolean; + public holidays: Holiday[]; + private queue: Queue; constructor ( @@ -173,6 +176,8 @@ export default class Pronote { // TODO: user.ressource.nbMaxJoursDeclarationAbsence; // TODO: user.ressource.listeGroupes + this.holidays = loginInformations.donnees.General.listeJoursFeries.V.map((holiday) => new Holiday(holiday)); + // For further requests, we implement a queue. this.queue = new Queue(); } diff --git a/src/index.ts b/src/index.ts index 3852346..7a58b0c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,6 +44,7 @@ export { PronoteApiUserMessageRecipientType } from "~/constants/recipients"; // Exporting main classes. export { default as Pronote } from "~/client/Pronote"; +export { default as Holiday } from "~/parser/holiday"; export { StudentSubject } from "~/parser/subject"; export { StudentAttachment } from "~/parser/attachment"; export { StudentHomework } from "~/parser/homework"; diff --git a/src/parser/holiday.ts b/src/parser/holiday.ts new file mode 100644 index 0000000..adceb8b --- /dev/null +++ b/src/parser/holiday.ts @@ -0,0 +1,36 @@ +import { PronoteApiLoginInformations } from "~/api"; +import { readPronoteApiDate } from "~/pronote/dates"; + +class Holiday { + readonly #id: string; + readonly #name: string; + + readonly #start: Date; + readonly #end: Date; + + constructor (data: PronoteApiLoginInformations["response"]["donnees"]["General"]["listeJoursFeries"]["V"][number]) { + this.#id = data.N; + this.#name = data.L; + + this.#start = readPronoteApiDate(data.dateDebut.V); + this.#end = readPronoteApiDate(data.dateFin.V); + } + + public get id (): string { + return this.#id; + } + + public get name (): string { + return this.#name; + } + + public get start (): Date { + return this.#start; + } + + public get end (): Date { + return this.#end; + } +} + +export default Holiday;