def profile(): if 'profilePic' in request.files and not allowed_file(request.files['profilePic'].filename): respo = ErrorResponse.ErrorResponseMessage( 'File not of type Image!', str(datetime.now()), 400, "", "/profile") return json.dumps(respo.__dict__), 400 if('userForm' not in request.form): respo = ErrorResponse.ErrorResponseMessage( 'Invalid Request!', str(datetime.now()), 400, "", "/profile") return json.dumps(respo.__dict__), 400 filename = None if 'profilePic' in request.files: file = request.files['profilePic'] filename = secure_filename(str(datetime.now())+"-"+file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) print("File Saved") apiObj = { 'requestPath': request.path, 'headers': {'Authorization': request.headers['Authorization']}, 'method': request.method, 'form': request.form['userForm'], 'file': filename if filename != None else "" } print(apiObj) rj.jsonarrappend('user', Path('.profileRequest'), apiObj) return jsonify( statusCode="200", message="Request Accepted" )
def comment(id=None, cid=None): if request.method == 'POST' and not request.json and 'text' not in request.json and len(request.json['text']) == 0: respo = ErrorResponse.ErrorResponseMessage( 'Comment cannot be empty', str(datetime.now()), 400, "", "/comment") return json.dumps(respo.__dict__), 400 # print(predict_prob([request.json['text']])) # print(pf.censor(request.json['text'])) # and predict_prob([request.json['text']]) > PROFANITY_IDX #and pf.is_profanerequest.json['text']: if request.method == 'POST' and check_profanity(request.json['text']): respo = ErrorResponse.ErrorResponseMessage( 'Offensive Comments are Not Allowed!', str(datetime.now()), 400, "", "/comments") username = jwt.decode( request.headers['Authorization'].split(' ')[1], verify=False) slack.post(attachments=[ { "fallback": "Plain-text summary of the attachment.", "color": "#FF0000", "pretext": "Offensive Comment - Error", "author_name": "Username - "+username['sub'], "title": "Comment Service", } ]) return json.dumps(respo.__dict__), 400 apiObj = { 'requestPath': request.path, 'headers': {'Authorization': request.headers['Authorization']}, 'method': request.method, 'body': request.json, 'service': 'comment' } print(apiObj) rj.jsonarrappend('tweet', Path('.tweetRequest'), apiObj) return jsonify( statusCode="200", message="Request Accepted" )
def tweet(id=None, cid=None): if request.method == 'POST' and 'file' in request.files and not allowed_file(request.files['file'].filename): respo = ErrorResponse.ErrorResponseMessage( 'File not of type Image!', str(datetime.now()), 400, "", "/tweet") return json.dumps(respo.__dict__), 400 if (request.method == 'POST' or request.method == 'PUT') and ('tweetForm' not in request.form or len(request.form['tweetForm']) == 0): respo = ErrorResponse.ErrorResponseMessage( 'Invalid Request!', str(datetime.now()), 400, "", "/tweet") return json.dumps(respo.__dict__), 400 if (request.method == 'POST' or request.method == 'PUT') and check_profanity(request.form['tweetForm']): respo = ErrorResponse.ErrorResponseMessage( 'Offensive Tweets are Not Allowed!', str(datetime.now()), 400, "", "/tweet") username = jwt.decode( request.headers['Authorization'].split(' ')[1], verify=False) slack.post(attachments=[ { "fallback": "Plain-text summary of the attachment.", "color": "#FF0000", "pretext": "Offensive Tweet - Error", "author_name": "Username - "+username['sub'], "title": "Tweet Service", } ]) return json.dumps(respo.__dict__), 400 filename = None if request.method == 'POST' and 'file' in request.files: file = request.files['file'] filename = secure_filename(str(datetime.now())+"-"+file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) print("File Saved") if request.method == 'POST' or request.method == 'PUT': apiObj = { 'requestPath': request.path, 'headers': {'Authorization': request.headers['Authorization']}, 'method': request.method, 'form': request.form['tweetForm'], 'file': filename if filename != None else "", 'service': 'tweet' } else: apiObj = { 'requestPath': request.path, 'headers': {'Authorization': request.headers['Authorization']}, 'method': request.method, 'service': 'tweet' } print(apiObj) rj.jsonarrappend('tweet', Path('.tweetRequest'), apiObj) return jsonify( statusCode="200", message="Request Accepted" )