| Total Complexity | 11 |
| Total Lines | 62 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
|
|
|||
| 2 | from __future__ import absolute_import, unicode_literals |
||
| 3 | from school_api.exceptions import SchoolException, LoginException |
||
| 4 | |||
| 5 | |||
| 6 | class UserType(): |
||
| 7 | ''' 用户类型参数 ''' |
||
| 8 | STUDENT = 0 |
||
| 9 | TEACHER = 1 |
||
| 10 | DEPT = 2 |
||
| 11 | |||
| 12 | |||
| 13 | class ScheduleType(): |
||
| 14 | ''' 课表类型参数 ''' |
||
| 15 | PERSON = 0 |
||
| 16 | CLASS = 1 |
||
| 17 | |||
| 18 | |||
| 19 | class LoginFail(): |
||
| 20 | ''' 登录失败返回错误信息 ''' |
||
| 21 | |||
| 22 | def __init__(self, tip=''): |
||
| 23 | self.tip = tip |
||
| 24 | |||
| 25 | def __getattr__(self, name): |
||
| 26 | def func(*args, **kwargs): |
||
| 27 | return {'error': self.tip}
|
||
| 28 | return func |
||
| 29 | |||
| 30 | def __nonzero__(self): |
||
| 31 | return True |
||
| 32 | |||
| 33 | |||
| 34 | def error_handle(func): |
||
| 35 | def wrapper(self, *args, **kwargs): |
||
| 36 | if not self.school.use_ex_handle: |
||
| 37 | return func(self, *args, **kwargs) |
||
| 38 | else: |
||
| 39 | try: |
||
| 40 | return func(self, *args, **kwargs) |
||
| 41 | |||
| 42 | except LoginException as reqe: |
||
| 43 | return LoginFail(reqe) |
||
| 44 | |||
| 45 | except SchoolException as reqe: |
||
| 46 | return {'error': reqe}
|
||
| 47 | return wrapper |
||
| 48 | |||
| 49 | |||
| 50 | def get_time_list(class_time): |
||
| 51 | time_list = {"1": [], "2": [], "3": [], "4": []}
|
||
| 52 | time_text = "{} ~ {}"
|
||
| 53 | for n, times in enumerate(class_time): |
||
| 54 | if n % 2 == 0: |
||
| 55 | time_list["1"].append(time_text.format(times[0], times[1])) |
||
| 56 | time_list["2"].append(time_text.format(times[0], class_time[n+1][1])) |
||
| 57 | |||
| 58 | if n < 8: |
||
| 59 | time_list["3"].append(time_text.format(times[0], class_time[n+2][1])) |
||
| 60 | time_list["4"].append(time_text.format(times[0], class_time[n+3][1])) |
||
| 61 | return time_list |
||
| 62 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.