def send_command_account(account_id=False): # if not account_id: raise HTTPError(404) # timestamp = datetime.datetime.now() # account_num = get_cfg_account_index(account_id) # if account_id == -1: raise HTTPError(404) # cmd_dict = request.json() # queue_item = {'timestamp': timestamp, 'response_queue': cfg.key_q_response_command, 'account_num': account_num, 'request': cmd_dict} # q_accounts[account_num].put(queue_item) # time.sleep(0.1) # while datetime.datetime.now() < (timestamp + datetime.timedelta(seconds=cfg.request_timeout)): if not q_dict[cfg.key_q_response_command].empty(): # rsp = q_dict[cfg.key_q_response_command].get() # if isinstance(rsp, bool): return HTTPResponse(status=200) if rsp else HTTPResponse(status=400) else: return HTTPResponse(body=str(rsp), status=200) if bool(rsp) else HTTPResponse(status=400) # raise HTTPError(500)
def web_accounts(account_id=False): # if not account_id: raise HTTPError(404) # # Get and check user user = _check_user(request.get_cookie('user')) if not user: redirect('/web/login') # account_num = get_cfg_account_index(account_id) # if account_id == -1: raise HTTPError(404) # timestamp = datetime.datetime.now() queue_item = {'timestamp': timestamp, 'response_queue': cfg.key_q_response_web_device, 'account_num': account_num, 'user': request.get_cookie('user')} # q_accounts[account_num].put(queue_item) # time.sleep(0.1) # while datetime.datetime.now() < (timestamp + datetime.timedelta(seconds=cfg.request_timeout)): if not q_dict[cfg.key_q_response_web_device].empty(): return create_device(user, q_dict[cfg.key_q_response_web_device].get(), '{account_name}'.format(account_name=get_cfg_account_name(account_id)), '{account_name}'.format(account_name=get_cfg_account_name(account_id))) # raise HTTPError(500)