def new_user(): username = request.json('username') password = request.json('password') email = request.json('email') status = controllers.create_new_user(username=username, password=password, email=email) return {'data': status}
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 creation_handler(): """Handles name creation""" try: data = request.json() if data is None: raise ValueError else: name = data['name'] #check for existence if name in _names: raise KeyError except ValueError: ##return 400 BadRequest response.status = 400 return except KeyError: ##if name already exist, return 409 conflict response.status = 409 return _names.add(name) # return 200 Success response.headers['Content-Type'] = 'application/json' return json.dumps({'name': name})
def alta(): try: data = request.json() except: raise ValueError return data
def save_configuration(): """Save the configuration to disk.""" config = userconfig.recover_or_create() settings = request.json() print('Saving settings: {}'.format(settings)) config['rmfriend']['address'] = settings['address'] config['rmfriend']['post'] = settings['post'] config['rmfriend']['username'] = settings['username'] config['rmfriend']['cache_dir'] = settings['cache_dir'] config.write() config = userconfig.recover_or_create() return json.dumps(dict(config['rmfriend']))
def post(): newdata = parser(request.json()) try: with open('database.json') as database: data = json.load(database) if data is None: data = [newdata] else: data.append(newdata) except FileNotFoundError: data = [newdata] print('exception') finally: with open('database.json', 'w') as database: json.dump(data, database) return {'status': 'ok'}
def set_options(): response.headers['Content-Type'] = 'application/json' response.headers['Cache-Control'] = 'no-cache' try: # parse input data try: data = request.json() except: raise ValueError if data is None: raise ValueError options = data.options print(options) return json.dumps({'result': 'ok'}) except ValueError: response.status = 400 return
def creation_handler(): """ method to handle name creation """ try: # parse input data try: data = request.json() except: raise ValueError if data is None: raise ValueError # extract and validate name try: if namepattern.match(data['name']) is None: raise ValueError name = data['name'] except (TypeError, KeyError): raise ValueError # check for existence if name in _names: raise KeyError except ValueError: # if bad request data, return 400 Bad Request response.status = 400 return except KeyError: # if name already exists, return 409 Conflict response.status = 409 return # add name _names.add(name) # return 200 Success response.headers['Content-Type'] = 'application/json' return json.dumps({'name': name})
def root(self): data = request.json() result = self.action(data) return json.dumps({'result': result})
def tag(): username = request.json('Username') + "\n" put_tagInstance(username) return username
def name(): username = request.json('Username') + "\n" return username
def getData(api): request = requests.get(api) request_json = request.json() return request_json
def return_data(): return request.json()
def user_login(): jsonData = request.json() user_email = jsonData['email'] password = jsonData['password']