| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -91,9 +91,7 @@ Here's the example from the :doc:`Intro <index>` again:: | |||
| 91 | 91 | s.logout() # see remark below | |
| 92 | 92 | ||
| 93 | 93 | ||
| 94 | - So what does this do? | ||
| 95 | - | ||
| 96 | - :: | ||
| 94 | + So what does this do?:: | ||
| 97 | 95 | ||
| 98 | 96 | # a minimal example, these parameters are absolutely neccessary | |
| 99 | 97 | s = webuntis.Session( | |
@@ -148,6 +146,33 @@ which you also can use to log yourself out automatically:: | |||
| 148 | 146 | ||
| 149 | 147 | # now you're logged out, even if your code halted with exceptions before. | |
| 150 | 148 | ||
| 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 | + | ||
| 151 | 176 | Where to go from here? | |
| 152 | 177 | ====================== | |
| 153 | 178 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,8 @@ Things you can do with the API | |||
| 25 | 25 | .. automethod:: holidays | |
| 26 | 26 | .. automethod:: klassen | |
| 27 | 27 | .. automethod:: timetable | |
| 28 | + .. automethod:: timetable_extended | ||
| 29 | + .. automethod:: my_timetable | ||
| 28 | 30 | .. automethod:: rooms | |
| 29 | 31 | .. automethod:: schoolyears | |
| 30 | 32 | .. automethod:: subjects | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -100,6 +100,12 @@ def login(self): | |||
| 100 | 100 | else: | |
| 101 | 101 | raise errors.AuthError('Something went wrong while authenticating', | |
| 102 | 102 | 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'] | ||
| 103 | 109 | ||
| 104 | 110 | return self | |
| 105 | 111 | ||
@@ -223,6 +229,10 @@ def timetable(self, start, end, **type_and_id): | |||
| 223 | 229 | ||
| 224 | 230 | @result_wrapper | |
| 225 | 231 | 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 | + """ | ||
| 226 | 236 | element_type_table = { | |
| 227 | 237 | 'klasse': 1, | |
| 228 | 238 | 'teacher': 2, | |
@@ -247,11 +257,25 @@ def timetable_extended(self, start, end, **type_and_id): | |||
| 247 | 257 | if element_type not in element_type_table: | |
| 248 | 258 | raise invalid_type_error | |
| 249 | 259 | ||
| 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 | + | ||
| 250 | 274 | options = self._create_date_param(end, | |
| 251 | 275 | start, | |
| 252 | 276 | element={ | |
| 253 | 277 | "id": int(element_id), | |
| 254 | - "type": element_type_table[element_type], | ||
| 278 | + "type": element_type_num, | ||
| 255 | 279 | }, | |
| 256 | 280 | onlyBaseTimetable=False, | |
| 257 | 281 | showBooking=True, | |
@@ -261,13 +285,11 @@ def timetable_extended(self, start, end, **type_and_id): | |||
| 261 | 285 | showLsNumber=True, | |
| 262 | 286 | showStudentgroup=True, | |
| 263 | 287 | ) | |
| 264 | - | ||
| 265 | 288 | parameters = { | |
| 266 | 289 | "options": options, | |
| 267 | 290 | } | |
| 268 | 291 | return objects.PeriodList, 'getTimetable', parameters | |
| 269 | 292 | ||
| 270 | - | ||
| 271 | 293 | @result_wrapper | |
| 272 | 294 | def rooms(self): | |
| 273 | 295 | """Get all rooms of a school. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,11 @@ class ResultWrapperMixin: | |||
| 33 | 33 | start: Union[datetime.datetime, datetime.date, int], | |
| 34 | 34 | end: Union[datetime.datetime, datetime.date, int], **type_and_id) -> objects.PeriodList: ... | |
| 35 | 35 | ||
| 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 | + | ||
| 36 | 41 | def rooms(self) -> objects.RoomList: ... | |
| 37 | 42 | ||
| 38 | 43 | def schoolyears(self) -> objects.SchoolyearList: ... | |
| Back | FazBrowse Home | New Git URL |
0 commit comments