async def messages(): """ API entry point for the bot. """ body = request.get_json() auth_header = request.headers[ "Authorization"] if "Authorization" in request.headers else "" print(f"body: {body}") print(f"auth_header: {auth_header}") response = await botp.process_message(body, auth_header) return simplejson.dumps(body, ignore_nan=True), 200
async def predict_stocks(storeId): '''REST API for requesting future sales of an item''' data = request.get_json() data = json.loads(data) logger.info("Received request by {} for predicting sales for" + "{} using {} days for the next {} days\n".format( storeId, data['itemName'], data['history'], data['days'] )) storeID = uuid.UUID(storeId) result = await _predict_stocks(storeID, data['itemName'], data['history'], data['days']) logger.info("Predictions for item {}, for storeId {}::{}".format( data['itemName'], storeId, result)) return Response( status=200, response=json.dumps(result) )
async def admin_settings(): if request.method == 'GET': return jsonify(dragon.tell()), 200 elif request.method == 'POST': return dragon.take(request.get_json(force=True)) return '', 204
def payload(self): """Store the input payload in the current request context""" return request.get_json()
def validate_wrap(*args, **kwargs): json_obj = request.get_json() for exp in expected_args: if exp not in json_obj: abort(400) return func(*args, **kwargs)