Created
April 27, 2018 08:12
-
-
Save phsheth/977f7a2adf9d03a939bfc45c7af191be to your computer and use it in GitHub Desktop.
This file contains 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, make_response, request | |
import io | |
import csv | |
import numpy as np | |
import pandas as pd | |
app = Flask(__name__) | |
def transform(text_file_contents): | |
return text_file_contents.replace("=", ",") | |
@app.route('/') | |
def form(): | |
return """ | |
<html> | |
<body> | |
<h1>Transform a file demo</h1> | |
<form action="/transform" method="post" enctype="multipart/form-data"> | |
<input type="file" name="data_file" /> | |
<input type="submit" /> | |
</form> | |
</body> | |
</html> | |
""" | |
@app.route('/transform', methods=["POST"]) | |
def transform_view(): | |
f = request.files['data_file'] | |
if not f: | |
return "No file" | |
stream = io.StringIO(f.stream.read().decode("UTF8"), newline=None) | |
csv_input = csv.reader(stream) | |
#print("file contents: ", file_contents) | |
#print(type(file_contents)) | |
#print(csv_input) | |
temp1 = [] | |
for row in csv_input: | |
print(row) | |
temp1.append(row) | |
stream.seek(0) | |
result = transform(stream.read()) | |
return temp1 | |
if __name__ == "__main__": | |
app.run(host='0.0.0.0', port=5001, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment