Examples

On this page you can find some examples on how to use the lectio.py library.

Authentication

To authenticate you need three things:

  • Your institution id

  • Your username

  • Your password

First you need your institution id. To get your institution id, you can simply go to your school’s lectio login page, and look at the url. It should look something like this:

The number after lectio is your institution id. (In this case 123)

We can now create a new lectio.Lectio object by creating a new file and adding the following code:

from lectio import Lectio

lec = Lectio(123, '<username>', '<password>')

Now we have a lectio.Lectio object, which we can use to get information from lectio.

Get my user object

Your user object contains information about you, such as your name and your id. It can also be used to fetch data such as your schedule, absences and more.

You can get your user object by calling the lectio.Lectio.get_user() method:

from lectio import Lectio

lec = Lectio(123, '<username>', '<password>')

me = lec.get_user()

The me variable now contains your user object. We can for example print your name:

print(me.name)

Get my schedule

You can get your schedule by calling the lectio.User.get_schedule() method with a start and end date:

from lectio import Lectio
from datetime import datetime

lec = Lectio(123, '<username>', '<password>')

me = lec.get_user()

schedule = me.get_schedule(datetime.now(), datetime.now())

The schedule variable now contains your schedule, which is a list of Module objects.

You might be wondering what the datetime.now() is. It is simply a date, and you can replace it with any date you want. In this example we are getting the schedule for today.

We can now loop through the schedule and print the name of each module:

for module in schedule:
    print(module.name)

You can read more about the Module object by going to the reference.

More to come…!