Completed
Push — master ( b31ded...2df684 )
by dai
02:11
created

school_api.client.utils   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
eloc 42
dl 0
loc 62
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A error_handle() 0 14 4
A get_time_list() 0 12 4
1
# -*- coding: utf-8 -*-
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
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():
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
20
    ''' 登录失败返回错误信息 '''
21
22
    def __init__(self, tip=''):
23
        self.tip = tip
24
25
    def __getattr__(self, name):
26
        def func(*args, **kwargs):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The argument kwargs seems to be unused.
Loading history...
Unused Code introduced by
The argument args seems to be unused.
Loading history...
27
            return {'error': self.tip}
28
        return func
29
30
    def __nonzero__(self):
31
        return True
32
33
34
def error_handle(func):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
35
    def wrapper(self, *args, **kwargs):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
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):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
51
    time_list = {"1": [], "2": [], "3": [], "4": []}
52
    time_text = "{} ~ {}"
53
    for n, times in enumerate(class_time):
0 ignored issues
show
Coding Style Naming introduced by
The name n does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
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