def get_available_rooms(cls, week: int, session: str, campus: str, building: str): """获得指定地点指定时间的可用教室""" resp = HttpRpc.call(method="GET", url=f'{cls.BASE_URL}/room/available?week={week}&session={session}&campus={campus}&building={building}', retry=True) if resp["status"] != "OK": raise RpcException('Entity returns non-success status') return resp["available_room"]
def get_rooms(cls) -> Dict[str, Dict[str, List[str]]]: """获得所有校区和楼栋的教室ID""" resp = HttpRpc.call(method="GET", url=f'{cls.BASE_URL}/room/', retry=True) if resp["status"] != "OK": raise RpcException('Entity returns non-success status') return resp["room_group"]
def get_card(cls, semester: str, card_id: str) -> CardResult: """ 根据学期和card ID获得card :param semester: 学期,如 2018-2019-1 :param card_id: card ID :return: """ resp = HttpRpc.call(method="GET", url=f'{cls.BASE_URL}/lesson/{card_id}/timetable/{semester}', retry=True) if resp["status"] != "success": raise RpcException('API Server returns non-success status') search_result = CardResult.make(resp) return search_result
def get_classroom_timetable(cls, semester: str, room_id: str): """ 根据学期和教室ID获得教室课表 :param semester: 学期,如 2018-2019-1 :param room_id: 教室ID :return: """ resp = HttpRpc.call(method="GET", url=f'{cls.BASE_URL}/room/{room_id}/timetable/{semester}', retry=True, headers={'X-Auth-Token': cls.REQUEST_TOKEN}) if resp["status"] != "success": raise RpcException('API Server returns non-success status') search_result = ClassroomTimetableResult.make(resp) return search_result
def get_teacher(cls, teacher_id: str): """ 根据教工号获得教师信息 :param teacher_id: 学号 :return: """ resp = HttpRpc.call(method="GET", url=f'{cls.BASE_URL}/teacher/{teacher_id}', retry=True, headers={'X-Auth-Token': cls.REQUEST_TOKEN}) if resp["status"] != "success": raise RpcException('API Server returns non-success status') search_result = TeacherResult.make(resp) return search_result
def get_student(cls, student_id: str): """ 根据学号获得学生信息 :param student_id: 学号 :return: """ resp = HttpRpc.call(method="GET", url=f'{cls.BASE_URL}/student/{student_id}', retry=True, headers={'X-Auth-Token': cls.REQUEST_TOKEN}) if resp["status"] != "success": raise RpcException('API Server returns non-success status') search_result = StudentResult.make(resp) return search_result
def get_teacher_timetable(cls, teacher_id: str, semester: str): """ 根据学期和教工号获得老师课表 :param teacher_id: 教工号 :param semester: 学期,如 2018-2019-1 :return: """ resp = HttpRpc.call(method="GET", url=f'{cls.BASE_URL}/teacher/{teacher_id}/timetable/{semester}', retry=True, headers={'X-Auth-Token': cls.REQUEST_TOKEN}) if resp["status"] != "success": raise RpcException('API Server returns non-success status') search_result = TeacherTimetableResult.make(resp) return search_result
def search(cls, keyword: str) -> SearchResult: """搜索 :param keyword: 需要搜索的关键词 :return: 搜索结果列表 """ keyword = keyword.replace("/", "") resp = HttpRpc.call(method="GET", url=f'{cls.BASE_URL}/search/query?key={keyword}', retry=True, headers={'X-Auth-Token': cls.REQUEST_TOKEN}) if resp["status"] != "OK": raise RpcException('API Server returns non-success status') search_result = SearchResult.make(resp) return search_result