File size: 2,144 Bytes
e28c9e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import json
from typing import Literal, Dict, List
from enum import Enum
from dataclasses import dataclass, field
from dataclasses_json import dataclass_json

class ErrorType(Enum):
    NONE = ""
    ID = "id"
    PASSWD = "passwd"
    CAPTCHA = "captcha"
    @staticmethod
    def from_error_message(error_msg: str) -> "ErrorType":
        if "用户名或密码错误" in error_msg:
            return ErrorType.ID
        elif "验证码错误" in error_msg:
            return ErrorType.CAPTCHA
        elif "密码错误" in error_msg:
            return ErrorType.PASSWD
        else:
            return ErrorType.NONE

@dataclass_json
@dataclass
class Course:
    course_id: str
    course_index: str

@dataclass_json
@dataclass
class CourseData:
    a: List[Course] = field(default_factory=list)  # 方案选课
    """

    方案选课

    """
    b: List[Course] = field(default_factory=list)  # 自由选课
    """

    自由选课

    """

@dataclass_json
@dataclass
class UserData:
    def __init__(self, std_id: str = "", password: str = "", course: CourseData = CourseData()):
        self.std_id = std_id
        self.password = password
        self.course = course 
    """

    用户数据

    """
    std_id: str
    """

    学号

    """
    password: str
    """

    密码

    """
    course: CourseData = field(default_factory=CourseData)
    """

    课程数据

    """
    @staticmethod
    def from_file(file_path: str) -> "UserData":
        with open(file_path, encoding="utf-8") as f:
            user_data_load = json.load(f)
            return UserData.from_dict(user_data_load)

@dataclass_json
@dataclass
class Setting:
    """

    全局设置

    """
    manual_login: bool = False
    """

    是否手动登录

    """
    browser: Literal["chrome", "edge"] = "edge"
    """

    使用的浏览器

    """
    @staticmethod
    def from_file(file_path: str) -> "Setting":
        with open(file_path, encoding="utf-8") as f:
            setting_load = json.load(f)
            return Setting.from_dict(setting_load)