FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

added session.login_result + docs · MarcProe/python-webuntis@deae40e · GitHub

Commit deae40e

Browse files
committed
added session.login_result + docs
1 parent fb297cd commit deae40e

4 files changed

Lines changed: 60 additions & 6 deletions

File tree

‎docs/quickstart.rst‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ Here's the example from the :doc:`Intro <index>` again::
9191
s.logout() # see remark below
9292

9393

94-
So what does this do?
95-
96-
::
94+
So what does this do?::
9795

9896
# a minimal example, these parameters are absolutely neccessary
9997
s = webuntis.Session(
@@ -148,6 +146,33 @@ which you also can use to log yourself out automatically::
148146

149147
# now you're logged out, even if your code halted with exceptions before.
150148

149+
150+
Get a timetable
151+
===============
152+
153+
Use one of the following::
154+
155+
monday = ...
156+
friday = ...
157+
158+
# klasse or teacher
159+
klasse = s.klassen().filter(name='KlassenName')[0]
160+
teacher = s.teachers().filter(name='ABC')[0]
161+
162+
# get info
163+
table = s.timetable(klasse=klasse, start=monday, end=friday).to_table()
164+
table = s.timetable(teacher=teacher, start=monday, end=friday).to_table()
165+
166+
167+
# get more info
168+
table = s.timetable_extended(klasse=klasse, start=monday, end=friday).to_table()
169+
170+
Use the logged-in user::
171+
172+
# same as timetable_extended using data from s.login_result
173+
table = s.my_timetable(start=monday, end=friday).to_table()
174+
175+
151176
Where to go from here?
152177
======================
153178

‎docs/session.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Things you can do with the API
2525
.. automethod:: holidays
2626
.. automethod:: klassen
2727
.. automethod:: timetable
28+
.. automethod:: timetable_extended
29+
.. automethod:: my_timetable
2830
.. automethod:: rooms
2931
.. automethod:: schoolyears
3032
.. automethod:: subjects

‎webuntis/session.py‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ def login(self):
100100
else:
101101
raise errors.AuthError('Something went wrong while authenticating',
102102
res)
103+
self.login_result = dict()
104+
if 'personType' in res:
105+
self.login_result['personType'] = res['personType']
106+
self.login_result['personId'] = res['personId']
107+
if "klasseId" in res:
108+
self.login_result['klasseId'] = res['klasseId']
103109

104110
return self
105111

@@ -223,6 +229,10 @@ def timetable(self, start, end, **type_and_id):
223229

224230
@result_wrapper
225231
def timetable_extended(self, start, end, **type_and_id):
232+
"""Get the timetable for a specific school class and time period.
233+
234+
Like timetable, but includes more info.
235+
"""
226236
element_type_table = {
227237
'klasse': 1,
228238
'teacher': 2,
@@ -247,11 +257,25 @@ def timetable_extended(self, start, end, **type_and_id):
247257
if element_type not in element_type_table:
248258
raise invalid_type_error
249259

260+
return self._timetable_extended_raw(end, start, element_id, element_type_table[element_type])
261+
262+
@result_wrapper
263+
def my_timetable(self, end, start):
264+
"""Get the timetable for the logged-in user.
265+
266+
see timetable_extended.
267+
"""
268+
return self._timetable_extended_raw(end, start,
269+
self.login_result['personId'], self.login_result['personType'])
270+
271+
272+
def _timetable_extended_raw(self, end, start, element_id, element_type_num):
273+
250274
options = self._create_date_param(end,
251275
start,
252276
element={
253277
"id": int(element_id),
254-
"type": element_type_table[element_type],
278+
"type": element_type_num,
255279
},
256280
onlyBaseTimetable=False,
257281
showBooking=True,
@@ -261,13 +285,11 @@ def timetable_extended(self, start, end, **type_and_id):
261285
showLsNumber=True,
262286
showStudentgroup=True,
263287
)
264-
265288
parameters = {
266289
"options": options,
267290
}
268291
return objects.PeriodList, 'getTimetable', parameters
269292

270-
271293
@result_wrapper
272294
def rooms(self):
273295
"""Get all rooms of a school.

‎webuntis/session.pyi‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class ResultWrapperMixin:
3333
start: Union[datetime.datetime, datetime.date, int],
3434
end: Union[datetime.datetime, datetime.date, int], **type_and_id) -> objects.PeriodList: ...
3535

36+
def my_timetable(self,
37+
start: Union[datetime.datetime, datetime.date, int],
38+
end: Union[datetime.datetime, datetime.date, int]
39+
) -> objects.PeriodList: ...
40+
3641
def rooms(self) -> objects.RoomList: ...
3742

3843
def schoolyears(self) -> objects.SchoolyearList: ...

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL