def post(self): args = reqparse.parse_args() username = args['username'] if not username: return {"message":"username not valid"},404 user = UserDao( email=args['email'], username=username, password=args['password'] ) if maintenanceDao.check_user_exist_by_email(user.email): return {"message": "Email already used"}, 202 elif maintenanceDao.check_user_exist_by_username(user.username): return {"message": "username already used pick another one"}, 202 user.password = user.generate_hash(user.password) try: maintenanceDao.insert_user (user) access_token = create_access_token (identity=user.username) refresh_token = create_refresh_token (identity=user.username) return { 'message': 'User {} was created'.format (user.username), 'access_token': access_token, 'refresh_token': refresh_token },201 except: return {'message': 'Something went wrong'}, 500 return{ 'message': 'User {0} was created'.format(user.username) }, 201
def post(self): parsed_args = reqparse.parse_args() order = Order(customer=parsed_args['customer']) order.normalized = normalizer(order.customer) db.session.add(order) db.session.commit() return order, 201
def post(self): args = reqparse.parse_args() username = args['username'] phone_number = args['phone_number'] password = args['password'] if not username: return {"message": "username not valid"} elif not phone_number: return {"message": "input phone number"} elif not password: return {"message": "input password"} user = UserApi(email=args['email'], phone_number=args['phone_number'], username=args['username'], password=args['password']) if userdao.check_user_exist_by_username(user.username): return {"message": "username already used"} else: user.password = user.generate_hash(user.password) userdao.insert_user(user) access_token = create_access_token(identity=user.username) refresh_token = create_refresh_token(identity=user.username) return { 'message': 'User{0} was created'.format(user.username), 'acess_token': access_token, 'refresh_token': refresh_token }
def post(self): current_user = get_jwt_identity() args = reqparse.parse_args() request = RequestDao(username=current_user, title=args['title'], description=args['description'], category=args['category']) return maintenanceDao.insert_request(request), 201
def put(self, name): data = reqparse.parse_args() item = ItemModel.find_by_name(name) if item: item.price = data['price'] else : new_item = ItemModel(name, data['price'], data['store_id']) new_item.save_to_db() return item.json()
def post(self): parsed_args = reqparse.parse_args() sku = SKU.query.filter_by(name=parsed_args['sku']).first() if not sku: abort(404, message="Product {} does not exists".format(parsed_args['sku'])) order_line = OrderLine(quantity=parsed_args['quantity'], sku=sku) db.session.add(order_line) db.session.commit() return order_line, 201
def put(self, id): parsed_args = reqparse.parse_args() order = Order.query.filter_by(id=id).first() if not order: order = Order(id=id) order.customer = parsed_args['customer'] order.normalized = normalizer(order.customer) db.session.add(order) db.session.commit() return order, 201
def put(self, id): parsed_args = reqparse.parse_args() sku = SKU.query.filter_by(id=id).first() if not sku: sku = SKU(id=id, name=parsed_args['name']) else: sku.name = parsed_args['name'] db.session.add(sku) db.session.commit() return sku, 201
def post(self): parser.add_argument('sync') args = parser.parse_args(req=request) if args['sync'] == '': stock_tushare.sync_daily() elif args['sync'] == '': stock_tushare.sync_week() else: return {'result': -1, 'message': '参数错误'} return {'result': 0, 'message': ''}
def post(self): parsed_args = reqparse.parse_args() sku = SKU.query.filter_by(name=parsed_args['sku']).first() if not sku: abort(404, message="Product {} does not exists".format( parsed_args['sku'])) storage = Storage(stock=parsed_args['quantity'], sku=sku) db.session.add(storage) db.session.commit() return storage, 201
def post(self): args = reqparse.parse_args() session = db_session.create_session() task = Task( title=args['title'], content=args['content'], subject=args['subject'], rating=args['rating'], ) session.add(task) session.commit() return jsonify({'success': 'OK'})
def predict(): reqparse.add_argument('text', type=str, required=True) reqparse.add_argument('model_endpoint', type=str, required=True) reqparse.add_argument('project', type=str, required=False) args = reqparse.parse_args() resp = sagemaker.predict(args.model_endpoint, {'text': args.text}) status_code = resp['ResponseMetadata']['HTTPStatusCode'] if status_code != 200: logger.error(resp) return error_response(status_code, 'Prediction unsuccessful.', error_type=resp['Error']['Code']) prediction = json.loads(resp['Body'].read()) return jsonify(prediction)
def post(self): args = reqparse.parse_args() user = User.query.filter_by(email=args.email).first() if not user: raise Forbidden('Email Error') if not user.verify_password(args.password): raise Forbidden('Password Error') token = user.generate_confirm_token() return { 'token': token, 'username': user.username, 'permission': user.role.permissions, 'avatar': user.avatar }
def endpoint_config(): reqparse.add_argument('model_endpoint', type=str, required=True) args = reqparse.parse_args() resp = sagemaker.predict(args.model_endpoint, { 'text': 'this is just a test', 'include_run_config': True }) status_code = resp['ResponseMetadata']['HTTPStatusCode'] if status_code != 200: logger.error(resp) return error_response(status_code, 'Getting config unsuccessful.', error_type=resp['Error']['Code']) prediction = json.loads(resp['Body'].read()) config = prediction['run_config'] return jsonify(config)
def endpoint_labels(): reqparse.add_argument('model_endpoint', type=str, required=True) args = reqparse.parse_args() resp = sagemaker.predict(args.model_endpoint, {'text': 'this is just a test'}) status_code = resp['ResponseMetadata']['HTTPStatusCode'] if status_code != 200: logger.error(resp) return error_response(status_code, 'Getting endpoint labels unsuccessful.', error_type=resp['Error']['Code']) prediction = json.loads(resp['Body'].read()) labels = prediction['predictions'][0]['labels_fixed'] label_vals = Predict.labels_to_int(labels) label_obj = {'labels': labels} if label_vals is not None: label_obj = {**label_obj, 'label_vals': label_vals} return jsonify(label_obj)
def post(self): """Creates a new ConfigMap""" args = reqparse.parse_args() configmap_data = { 'kind': 'ConfigMap', 'apiVersion': api_version, 'metadata': { 'name': 'configurator-configmap' }, 'data': { 'auth_type': args['auth_type'], 'workshop_name': args['workshop_name'] } } with open(configmap_file, 'w') as outfile: json.dump(configmap_data, outfile) return {'configmap': configmap_data}, 201
def get(self): parser.add_argument('type') parser.add_argument('position') args = parser.parse_args(req=request) stock_tushare.sync_daily() return {'result': 0, 'message': ''}
def list_endpoints(): reqparse.add_argument('active', type=bool, required=False, default=False) args = reqparse.parse_args() endpoints = sagemaker.list_endpoints(active=args.active) return jsonify(endpoints)
def post(self): parsed_args = reqparse.parse_args() sku = SKU(name=parsed_args['name']) db.session.add(sku) db.session.commit() return sku, 201
def delete_model(): reqparse.add_argument('model_name', type=str, required=True) args = reqparse.parse_args() resp = sagemaker.delete_model(model_name=args.model_name) return success_response(200, 'Successfully created endpoint.')
def post(self): args = reqparse.parse_args() booking = models.Booking.query.filter_by(id=args['booking']).one() booking.status = 0 db.session.add(booking) db.session.commit()
def post(self): args = reqparse.parse_args()
def post(self): print("receive post...") args = reqparse.parse_args() name = args['name'] return "hello " + name + " " + str(datetime.date.today())