Created
August 2, 2019 13:23
-
-
Save baffioso/ead9330ffc78cd478272f42a4218ca70 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, jsonify | |
app = Flask(__name__) | |
def validate_data_format(data): | |
valid_data = True | |
messages = [] | |
# Check number of rows in each col | |
length = len(data[list(data.keys())[0]]) | |
for i in list(data.keys())[1:]: | |
if length != len(data[i]): | |
message = ('Different length of row in col: {i}') | |
messages.append(message) | |
valid_data = False | |
# Check data types | |
if valid_data: | |
return True | |
else: | |
return messages | |
@app.route('/upload', methods = ['POST']) | |
def post_data(): | |
data = request.get_json() | |
validate_data_format(data) | |
return jsonify(data), 200 | |
if __name__ == '__main__': | |
app.run(debug = True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment