Skip to content

This is a small api wrapper to get data from your Lessons.

License

Notifications You must be signed in to change notification settings

elias-knodel/WebUntis-LessonTopic-PY

Repository files navigation

WebUntis API for Lessontopics in Python

gh-commit-badge gh-contributors-badge gh-stars-badge

Description

I don't like python but oh well here I am...
This was made entirely in my free time and is in no way associated with any business.
It is my first python project so mistakes can happen so please keep that in mind.

Getting started

  1. Copy env file
cp .env.example .env
  1. Fill in your login credentials into the .env file.
    (Don't worry, the .env does not get committed so your secrets are safe there)

  2. If you want an example of how this works go to /webuntis_example.py

How to use

In code

import webuntis
import cache
from decouple import config

# Get login credentials from env file
username = config('USERNAME')
password = config('PASSWORD')
server = config('SERVER')
school = config('SCHOOL')

# Create WebUntis API Wrapper Object
client = webuntis.Webuntis(username, password, server, school)

# Log the client in webuntis
client.login()

# This gets all lessons in all your school-years and saves them into a cache file
cacheL = cache.Cache("lessons")
isValidLT = cacheL.verify()

if not isValidLT:
    lessons = client.get_all_lessons()
    cacheL.write(json_data=lessons)

# This gets all lessons in a day in all years and loops over them
# Then it saves the topics of each lesson into a cache file
cacheLT = cache.Cache("lessontopics")
isValidLT = cacheLT.verify()

if not isValidLT:
    lesson_topic_dict = {}

    for year in cacheL.read():
        for lesson in year:
            index_day = lesson["date"]
            index_lesson = lesson["startTime"]

            if lesson_topic_dict.get(index_day) is None:
                lesson_topic_dict[index_day] = []

            lesson_topic_dict[index_day].append(client.get_lesson_topic(lesson))

    cacheLT.write(json_data=lesson_topic_dict)

# Log the client out
client.logout()

# Now you can access the data by reading the cache
cacheLT.read()

Data Structure

So you can access the lesson topics with cacheLT.read() now... But what does it return?

Here is an example:

{
    "20220919": [
        {
            "startTime": 925,
            "subject": "D",
            "subjectLong": "Deutsch",
            "topic": "Aufgaben"
        },
        {
            "startTime": 1010,
            "subject": "E",
            "subjectLong": "Englisch",
            "topic": "Assignments"
        }
    ]
}

Contributing

If you want to take part in contribution, like fixing issues and contributing directly to the code base, plase visit the How to Contribute document.

Useful links

License - Contributing - Code of conduct - Issues - Pull requests


Copyright (c) Elias Knodel. All rights reserved | Licensed under the MIT license.

About

This is a small api wrapper to get data from your Lessons.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published