Magister Exporter (Home Assistant) banner

Magister Exporter (Home Assistant)

3 devlogs
10h 30m 29s

A Home Assistant add-on that will automatically get your Magister calendar. (Magister is a Dutch school organisation app)

This project uses AI

I only used AI to debug the HTTP server part of my program, the rest was all made by hand or with help from documentation or forums

Repository

Loading README...

DjaydenR

OHHHH MYY GODDD, FINALLY!!! After around 3 hours of debugging (programming time, not real time, which was probably around 5 hours), it finally works. I now have a Home Assistant add-on that actually works.
At first I had problems with Selenium, so I replaced it with Playwright, but that still caused issues. Apparently there are no Playwright builds for ARMv7, which is what my Raspberry Pi 2B (Home Assistant server) uses. I thought I could fix this problem, but I couldn’t. I am planning on upgrading to a Raspberry Pi 5 in the future, but for now I had to spin up a Home Assistant virtual machine on my PC and run the add-on there.
I also had issues with placing the add-on locally, so I had to remake the repository so it could be added as an add-on in Home Assistant.
I know this is a really bland explanation of what I did, but it is 23:15 right now (that is 11:15 PM in American) and I haven’t even looked at my math and German homework, so I am going to call it quits.

Attachment
0
DjaydenR

I fully rewrote the program into a Home Assistant app (that’s their new name for add-ons). So now it has a config.yaml defining all the options the program will use and a Dockerfile with the instructions for making the container. I also merged the Selenium and Magister fetching code into one module that main.py imports.

So I added all of this into the Home Assistant add-on folder and then tried to install the app. But I was hit with an error. It was extremely long but boiled down to gcc being missing, so I added that to the Docker instructions, but there was still a giant, slightly different, error. So after a few times of playing wack-a-mole with all the missing dependencies, it finally installed. But when I tried to run it I was hit with yet another error, the key part of the error was this: “selenium Unable to obtain driver for chrome”, I searched for this error and found this on the Selenium site: “If you are running […] or a Raspberry Pi, Selenium Manager will not work for you”

This is not limited to just Selenium Manager; Selenium just doesn’t work on a Raspberry Pi, which is what I use to run Home Assistant. So basically, I fully need to replace Selenium with another managed browser. Luckily I know that Playwright works on Home Assistant (I didn’t use it because I was told that Selenium is better, but I don’t recall why it was better). I had used Playwright before for a Home Assistant app and I also checked and Playwright can manage network request, so back to rewriting half the program (it isn’t that much work, but you need to have some drama in a story).

Oh, and BTW, I made a logo for my program when I was done with debugging my program (see images). It is just ripping off two logos by pasting them together, but I am still proud of it. I also made it into a vector using an online tool.

PS (didn’t know where to put this): I love how the configuration options look, they look so clean (see images)

Attachment
Attachment
Attachment
Attachment
Attachment
0
DjaydenR

My project will consist of two parts, one that will fetch my Magister bearer token and one that will fetch my calendar.

The first part will use a managed browser to go to Magister, enter my credentials it fetched from credentials.json, and then listen for a network request containing my token (see video). Also, sorry for the giant watermark, I was at school and only have a Chromebook. The token, along with my user_id, is then saved again to credentials.json (see image).

The second piece of code then uses this token to make a request to Magister, the url for this looks like this (translated from Dutch):
/api/people/{user_id}/appointments?status=1&until={end_date}&from={begin_date}
For now I have just hard-coded the end date, but I plan on making it dynamic using datetime. The output of this request is a gigantic mess, it contains so many duplicate entries and irrelevant data. Luckily I already did some work before this project, so I can roughly show my schedule I got (see image). This schedule shows the lesson hour, the subject, the teacher, the class, and then the classroom number.

This output looks like a mess and is far from standardised. I plan on using ical to format my whole agenda, this is going to take a whole lot of work.

Also, the end goals is making this a Home Assistant add-on, so I will also have to make this a loop that checks when the token needs to be refreshed and fetches my calendar and hosts it on a local port. I think this would be the cleanest way. The calendar could then be added again in Home Assistant.

Attachment
Attachment
0