Created
April 28, 2021 11:19
-
-
Save elias-knodel/68170188766956d9475cf99eeed9e260 to your computer and use it in GitHub Desktop.
Web Untis get Lesson Topic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| untis.getLessonTopic( | |
| e.date, // Lesson Date / Day | |
| e.startTime, // Lesson start time | |
| e.endTime, // Lesson end time | |
| e.id // Lesson ID | |
| ).then(res => { | |
| response = <string>res; | |
| // Do something with your Data here | |
| }).catch(err => { | |
| console.log(err); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { AxiosInstance } from "axios"; | |
| import WebUntis from "webuntis"; | |
| export class WebUntisCustom extends WebUntis { | |
| private axiosInstance: AxiosInstance; | |
| private buildCookiesCustom: Function; | |
| constructor( | |
| school: string, | |
| username: string, | |
| password: string, | |
| baseurl: string, | |
| identity: string = "Awesome" | |
| ) { | |
| super(school, username, password, baseurl, identity); | |
| // @ts-ignore | |
| this.axiosInstance = <AxiosInstance>this["axios"]; | |
| this.buildCookiesCustom = this["_buildCookies"]; | |
| } | |
| /** | |
| * Get Topic of lesson | |
| * @param {boolean} [validateSession=true] | |
| * @returns {Promise<String>} | |
| */ | |
| async getLessonTopic( | |
| date: number, | |
| startTime: number, | |
| endTime: number, | |
| selectedPeriodId: number, | |
| validateSession = true | |
| ) { | |
| if (validateSession && !(await this.validateSession())) | |
| throw new Error("Current Session is not valid"); | |
| const response = await this.axiosInstance({ | |
| method: "GET", | |
| url: "/WebUntis/api/public/period/info?date=" + date + | |
| "&starttime=" + startTime + | |
| "&endtime=" + endTime + | |
| "&elemid=10487" + | |
| "&elemtype=5" + | |
| "&ttFmtId=1" + | |
| "&selectedPeriodId=" + selectedPeriodId, | |
| headers: { | |
| Cookie: this.buildCookiesCustom() | |
| } | |
| }); | |
| const lessonTopicRes: String = response.data.data.blocks[0][0].lessonTopic.text; | |
| try { | |
| if (typeof lessonTopicRes !== "string") | |
| console.log("Server returned invalid data."); | |
| // remove linebreaks with regex and replace | |
| return lessonTopicRes.replace(/(\r\n|\n|\r)/gm, " "); | |
| } catch (err) { | |
| console.log("Server returned no data."); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment