Introduction¶
This is an introduction guide for OpenTamPy, a high-level API wrapper, written in :py: , designed to help in the creation of scripts that use data of the intranet.tam.ch.
Prerequisites¶
OpenTamPy works best with Python 3.9 and higher. Lower versions may work, but support is not guaranteed.
Installation guide¶
This is a guide to install the library with pip
On Windows:
$ py -3 -m pip install OpenTamPy
On other systems:
$ python3 -m pip install OpenTamPy
If you’re installing from source, to install all dependencies run the following command:
On Windows:
$ py -3 -m pip install requirements.txt
On other systems:
$ python3 -m pip install requirements.txt
A basic script¶
Simple example that fetches all lessons for the current week and prints their abbreviation
Save this as example.py
from OpenTamPy import Intranet
username = "YOURUSERNAME"
password = "YOURPASSWORD"
school = "krm"
instance = Intranet(username, password, school)
timetable = instance.get_timetable()
for lesson in timetable:
print(lesson.courseName)
Lets walk through this:
The first line imports the package. If this raises a
ModuleNotFoundErroror anImportError, please make sure you have the library correctly installedAfter this set the
usernameand thepasswordvariable by replacing said strings. The schoolcode can be found as part of the URL. An example would behttps://intranet.tam.ch/krm/,krmwould be the schoolcodeInitiate an instance of the Intranet class by calling the class with your authentication details. instance is now a Intranet object from which all of the libraries functions will be called. This object contains all the relevant information to communicate with the intranet.
Fetch the whole timetable for the current week. You could also pass arguments into the getTimetable function to specify the range of what should be returned
Iterate over the list of lessons and print the wanted attribute.
Now run the script with the following command:
On Windows:
$ py -3 example.py
On other systems:
$ python3 example.py