def get(self): parser = reqparse.RequestParser() parser.add_argument('init', type=str, location='args') parser.add_argument('start', type=str, location='args') args = parser.parse_args() if args['init'] is not None: globalvar.add({'exam': console.Exam()}) return [{'status': 100, 'message': ''}] elif args['start'] is not None: if globalvar.get('exam'): globalvar.get('exam').start() return [{'status': 100, 'message': ''}] return [{'status': 404, 'message': '参数错误'}]
def post(self): parser = reqparse.RequestParser() parser.add_argument('index', type=int, location='form') parser.add_argument('instance_name', type=str, location='form') parser.add_argument('student_num', type=str, location='form') parser.add_argument('pwd', type=str, location='form') parser.add_argument('ver_code', type=str, location='form') parser.add_argument('op', type=str, location='form') args = parser.parse_args() con = globalvar.get(args['instance_name']) if args['op'] == 'init': if globalvar.get(args['instance_name']): con.quit() globalvar.add({args['instance_name']: console.Console()}) return [{'status': 100, 'message': ''}] elif args['op'] == 'select_school': if args['index'] is not None: if con.status['search_school'] and not con.status['login']: return [{ 'status': 100, 'message': '', 'data': con.select_school(args['index']) }] else: return [{'status': 404, 'message': '先搜索学校'}] elif args['op'] == 'login': # print(con.get_login_ver_code()) # ver_code = args['ver_code'] # ver_code = rk_code(con.get_login_ver_code()) ver_code = rk_code(con.get_login_ver_code(refresh=True)) if args['student_num'] and args['pwd'] and ver_code: tmp = con.login(args['student_num'], args['pwd'], ver_code) while tmp[0] == '验证码错误': time.sleep(1) ver_code = rk_code(con.get_login_ver_code(refresh=True)) tmp = con.login(args['student_num'], args['pwd'], ver_code) if tmp[1]: return [{'status': 100, 'message': '', 'data': tmp[0]}] else: return [{'status': 404, 'message': tmp[0]}] elif args['op'] == 'browse_watch': if args['index'] is not None: return [{ 'status': 100, 'message': '', 'data': con.browse_watch(args['index']) }] return [{'status': 404, 'message': '参数错误'}]
def get(self): parser = reqparse.RequestParser() parser.add_argument('op', type=str, location='args') parser.add_argument('instance_name', type=str, location='args') parser.add_argument('school_name', type=str, location='args') # parser.add_argument('get_ver_code', type=bool, location='args') parser.add_argument('author', type=str, location='args') args = parser.parse_args() con = globalvar.get(args['instance_name']) if args['author']: return [{'author': __author__}] if args['op'] == 'search_school': tmp = con.search_school(args['school_name']) return [{'status': 100, 'message': '', 'data': tmp}] elif args['op'] == 'get_course': if con.status['login']: tmp = con.get_course() return [{'status': 100, 'message': '', 'data': tmp}] return [{'status': 404, 'message': '参数错误'}]