API Reference

The following section gives you a clearer insight into the functions of OpenTamPy

Note

As objects are constructed directly from their Intranet response, there is no guarantee that their attributes will persist over all time. Therefore it is considered best practice to implement a try-except block for AttributeErrors

The Intranet class

OpenTamPy is based on this class and a few helper functions, to help you achieve your goal. All functions and attributes of the library can be called from this class For an asynchronous version of this class refer to Async

class Intranet(username, password, school, debug=False)

This is the base class from where you can call all the libraries functions from. To be able to do this, you need to create an instance of this class first.

Parameters
  • username (str) – Your Intranet username. This is only used for authentication purposes

  • password (str) – Your Intranet password. This is only used for authentication purposes

  • school (str) – Your schoolcode. Ex: krm for MNG, krr for RGZH. Can be found in the URL. Ex: In https://intranet.tam.ch/krm/, where krm would be the schoolcode

  • debug (bool) – Whether logging should be set to debug. Defaults to False

get_timetable(start_date=0, end_date=0, user_id=None, timeout=20)
Parameters
  • start_date (int) – Start of the timebracket as ‘DD.MM.YY’, defaults to last monday

  • end_date – End of the timebracket as ‘DD.MM.YY’, defaults to next sunday

  • user_id – Fetch timetable for any student with the given Id

  • timeout (int) – Passed through to the request, increase if you request large amounts of data, as it might take longer to process than the default.

It is possible to fetch someone elses timetable if only their studentID is given, which can be acquired by running get_class_mates. Whether this is intentional or not is unclear, so this might be removed at any time

Yield

lesson

get_absences()

This function fetches a list of all absences and returns an Iterator containing objects from which you can get information very easily.

instance = Intranet(username, password)
absenceIterator = instance.get_absences()
for absence in absenceIterator:
    print("Name of teacher", absence.Lehrperson)
Returns

absence

get_lesson_absence_data(lesson)

This function fetches the absence data corresponding to the lesson passed through You can also pass through a list of lesson objects, and the function will return a list of the corresponding values

Parameters

lessonlesson

Returns

If the parameter was a lesson, returns a list of lesson object, otherwise only a lesson object

get_class_mates()

This function fetches a list of each classMate and yields it back

Yield

ClassMate

get_class_teachers()

This function fetches a list of each teacher and yields it back

Yield

teacher

set_homework_data(lesson, title, description)
Parameters
  • title (str) – Title for absence to be set

  • description (str) – Description for absence to be set

Raises

MissingPermission – Not enough permissions

Set homework data for passed through lesson, returns new homework data

delete_homework_info(lesson)
Parameters

lesson – Lesson object for which the absence should be deleted

Raises

MissingPermission – Not enough permissions

Deletes all homework associated with that lesson

get_additional_homework_info(lesson)
Parameters

lesson – Lesson object for which the homework info should be fetched

The resource object

class resource
classes: list

list contains class objects documented below

class class
classCommonName: str
classId: int
classLevel: str
className: str
classShort: str
occupied: int
periodId: int
courses: list

list contains course objects documented below

class course
course: str

Name of the course. Ex: Anwendungen der Mathematik

courseId: int
courseShort: str

Short name of the course. Ex: AM

courseShortWithClasses: str

Short Name containing classes. Ex: AM (6x, 6x, 6x, 6x)

periodId: str
studentId: list[int]

List of all students

studentName: str

All student names separated by a semicolon

subjectId: int
resources: list
class resource
description: str

Description of resource

resource: str

Resource

resourceCategory: str
resourceId: int
sort1: str
sort2: str
rooms: list

list containing room objects

class room
building: str
description: str
occupied: int
room: str
roomCategory: str
roomId: int
sort1: str
students: list

List containing student objects

teachers: list

List containing teacher objects

class teacher
acronym: str
name: str

Name of the teacher

occupied: int
personId: int

ID of teacher

The absence object

This object contains attributes constructed directly from an intranet response, which contains multiple absence objects. Each absence object represents one absence and thereby its attributes. The following attributes are documented, but may change at any time without notice

class absence
Kurs_Anlass: str

Name of the course

Datum: str

Date of the absence in the format DD.MM.YYYY

Zeit_Anzahl_Lekt: str

Time of the start of the absence in the format HH:MM

Lehrperson: str

Name of the teacher

Absenzgruppe: str

Type of the absence, seems to be mostly “Absenz”

Status: str

Whether the absence has been excused or not

PersonID: str

Intranet ID for the person you’re fetching the absence of

AbsenceEventID: str

Intranet ID for the absence itself

The lesson object

This object contains attributes constructed directly from an intranet response, which contains multiple timetable objects. Each absence object represents a lesson and thereby its attributes. The following attributes are documented, but may change at any time without notice, as the Intranet changes quite frequently. I will do my best to keep this documentation updated

class lesson
id: int

Intranet ID for the lesson

timetableElementId: int

Intranet ID for the position in grid

holidayId: int
    • holidayId

    • Info

    • 0

    • No holiday

blockId: list[int]

contains a list with other ids, that it is connected to in a block

blockTeacherId: list[int]

contains a list of all teacher ids connected to the block

blockClassId: list[int]

used to represent multiple lessons together with each id being a lesson, empty if theres no associated lessons

blockRoomId: list[int]
modId: int
periodId: int
start: str

represented as “/Date(UNIX timestamp)/”

end: str

represented as “/Date(UNIX timestamp)/”

lessonDate: str

represented as “YYYY-MM-DD”

lessonStart: str

represented as “HH:MM:SS”

lessonEnd: str

represented as “HH:MM:SS”

lessonDuration: str

Duration of lesson as “HH:MM:SS.000000”.

nbrOfModifiedLesson: str
connectedId: None

Appears to always be ‘None’

isAllDay: int
timetableEntryTypeId: int
timetableEntryType: str
timetableEntryTypeLong: str

Known IDs:

timetableEntryTypeId

timetableEntryType

timetableEntryTypeLong

timetableEntryTypeShort

1

lesson

lesson

lesson

11

substitution

canceled lesson

cancel

12

substitution

block substitution

block

15

substitution

holiday

holiday

16

lesson

modified lesson

modlesson

messageId: int

Id of the attribute message below

message: str

Message by the Intranet. Some examples might be:

  • “Exkursion”

  • “Gesamtkonvent, Aula”

  • “Instrumentalunterricht findet statt!”

output: str

Is either a newline or “None”

title: str

Title of the lesson, some examples are “E”, “F” or “M”

halfClassLesson: unknown/None
courseId: int

Id of the course.

courseName: str

Name of the course. Examples are “Ch”, “D”, “E” and “Sp”

course: str

Long name of the course. Some examples are:

  • “Biologie, SP DjTj (4x )”

  • “Deutsch, GF DjTj (4x )”

  • “Mathematik, GF DjTj (4x )”

courseLong: str

Empty string

isExamLesson: bool

Always False even if lesson contains an exam

isCheckedLesson: bool

Always False even if lesson is checked

lessonAbsenceCount: int

Amount of absent people during the lesson

subjectId: int

subjectId

subjectName

0

None

1

Deutsch

2

Französisch

4

Englisch

9

Mathematik

12

Chemie

13

Biologie

15

Geschichte

16

Einführung in Wirtschaft und Recht

23

Sport

24

Informatik

37

Klassenstunde

3, 5, 6, 7, 8, 10, 11, 14, 17-22, 25-36

unknown

subjectName: str

Name of the subject

timegridId: int
classId: list[int]

Id of the class. If it is a block, it contains multiple ids Can be mapped to className, as they directly correspond with each other.

ex: classId “1618” belongs to className “4e”

className: str

Name of the class. If there are multiple, they are sorted like “4a, 4b, 4c” Can be mapped to classId, as they directly correspond with each other.

ex: classId “1618” belongs to className “4e”

profileId: int

Profile Id

teamId: str

Empty string

teacherId: list[int]
teacherAcronym: str
teacherFullName: list[str]
teacherLastName: str

Empty string

teacherFirstName: str

Empty string

connectedTeacherId: list[int]
connectedTeacherFullName: str
student: list[:class:`student`]
studentId: int
studentFullName: str

Empty string

studentFirstname: str

Empty string

roomId: list[int]
roomName: str
locationDescription: str
resourceId: list
timetableClassBookId: int
hasHomework: bool
hasHomeworkFiles: bool
hasExam: bool

Whether the lesson is an exam lesson. As of 16/09/21, this is false even if there is an exam. The only way to check whether there is an exam is if the string “(!)” is contained in lesson.title

hasExamFiles: bool
privileges: unknown/None
resource: unknown/None
reservedResources: int
totalStock: int
school: str
relatedId: list[str]

The student object

This object contains attributes constructed directly from an intranet response Each student object represents a student and thereby its attributes. The following attributes are documented, but may change at any time without notice

class student
studentId: int
studentName: str

The ClassMate object

This object contains attributes constructed directly from an intranet response Each object represents a student and thereby its attributes. The following attributes are documented, but may change at any time without notice

class ClassMate
EMail: str

Email of a student

Klasse: str

Class the student is in

Mobile: str

Phone number of student

Name: str

Last name of student

PersonID: str

Same as the studentId from student, may possibly be used to request their timetable?

Telefon: str

Phone number of student

Vorname: str

First name of student

zust_SL: str

responsible schoolmanager

The teacher object

This object contains attributes constructed directly from an intranet response Each object represents a student and thereby its attributes. The following attributes are documented, but may change at any time without notice

class teacher
Adresse: str

Address of teacher

CourseID: str

Id of the course the teacher is responsible for

Email: str

Email of the teacher

EndDate: str

Date as DD.MM.YYYY

Kurs: str

Name of the teachers course

Name: str

Last name of the teacher

PLZOrt: str

Place and Postcode of teacher

PersonID: str

Id of teacher

StartDate: str

Date as DD.MM.YYYY

Telefon: str

Phone number of teacher

Vorname: str

First name of teacher