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

remove duplicated code · robquant/python-webuntis@34519be · GitHub

Repository navigation

Commit 34519be

Browse files
committed
remove duplicated code
1 parent d21766a commit 34519be

1 file changed

Lines changed: 14 additions & 46 deletions

File tree

‎webuntis/session.py‎

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,9 @@ def timetable(self, start, end, **type_and_id):
217217
# if we have to deal with an object in element_id,
218218
# its id gets placed here anyway
219219

220-
json_start = utils.datetime_utils.format_date(start)
221-
json_end = utils.datetime_utils.format_date(end)
222-
223-
if json_start > json_end:
224-
raise ValueError('Start can\'t be later than the end.')
225-
226-
parameters = {
227-
'id': int(element_id),
228-
'type': element_type_table[element_type],
229-
'startDate': json_start,
230-
'endDate': json_end
231-
}
232-
220+
parameters = self._create_date_param(end, start,
221+
id=int(element_id), type = element_type_table[element_type])
222+
parameters = parameters["options"] # getTimetable is without options!
233223
return objects.PeriodList, 'getTimetable', parameters
234224

235225
@result_wrapper
@@ -297,21 +287,7 @@ def substitutions(self, start, end, departmentId=0):
297287
:rtype: :py:class:`webuntis.objects.SubstitutionList`
298288
"""
299289

300-
json_start = utils.datetime_utils.format_date(start)
301-
json_end = utils.datetime_utils.format_date(end)
302-
303-
if json_start > json_end:
304-
raise ValueError('Start can\'t be later than the end.')
305-
306-
parameters = {
307-
'startDate': json_start,
308-
'endDate': json_end,
309-
'departmentId': departmentId
310-
}
311-
312-
# if departmentId:
313-
# parameters['departmentId'] = departmentId
314-
290+
parameters = self._create_date_param(end, start, departmentId = departmentId)
315291
return objects.SubstitutionList, 'getSubstitutions', parameters
316292

317293
@result_wrapper
@@ -359,18 +335,7 @@ def exams(self, start, end, examTypeId=0):
359335
:rtype: :py:class:`webuntis.objects.ExamsList`
360336
"""
361337

362-
json_start = utils.datetime_utils.format_date(start)
363-
json_end = utils.datetime_utils.format_date(end)
364-
365-
if json_start > json_end:
366-
raise ValueError('Start can\'t be later than the end.')
367-
368-
parameters = {
369-
'startDate': json_start,
370-
'endDate': json_end,
371-
'examTypeId': examTypeId
372-
}
373-
338+
parameters = self._create_date_param(end, start, examTypeId = examTypeId)
374339
return objects.ExamsList, 'getExams', parameters
375340

376341
@result_wrapper
@@ -386,20 +351,23 @@ def timetableWithAbsences(self, start, end):
386351
:rtype: :py:class:`webuntis.objects.AbsencesList`
387352
"""
388353

354+
parameters = self._create_date_param(end, start)
355+
356+
return objects.AbsencesList, 'getTimetableWithAbsences', parameters
357+
358+
@staticmethod
359+
def _create_date_param(end, start, **kwargs):
389360
json_start = utils.datetime_utils.format_date(start)
390361
json_end = utils.datetime_utils.format_date(end)
391-
392362
if json_start > json_end:
393363
raise ValueError('Start can\'t be later than the end.')
394-
395364
parameters = {
396-
"options": {
365+
"options": dict({
397366
'startDate': json_start,
398367
'endDate': json_end,
399-
}
368+
}, **kwargs)
400369
}
401-
402-
return objects.AbsencesList, 'getTimetableWithAbsences', parameters
370+
return parameters
403371

404372

405373
class Session(JSONRPCSession, ResultWrapperMixin):

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL