Last active
January 21, 2020 22:46
-
-
Save ggodreau/d56a2bc87654f3433b3b3dbcf3773f09 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
import pandas as pd | |
import io | |
from flask import Flask, make_response | |
app = Flask(__name__) | |
@app.route('/', methods=['GET', 'POST']) | |
def hello_world(request): | |
"""Responds to any HTTP request. | |
Args: | |
request (flask.Request): HTTP request object. | |
Returns: | |
The response text or any set of values that can be turned into a | |
Response object using | |
`make_response <http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>`. | |
""" | |
raw_text = request.form.get('raw_text') | |
raw_date = request.form.get('raw_date') | |
raw_csv = request.files.get('raw_csv').read() | |
print(f'raw_text: {raw_text}') | |
print(f'raw_date: {raw_date}') | |
print(f'raw_csv: {raw_csv}') | |
print(f'{pd.__version__}') | |
# can't do this: | |
# print(f'csv3 head regular bytes: {pd.read_csv(csv3).head(1)}') | |
# flask.Response('', headers={'Content-Type': 'text/html'}) | |
# return str(pd.read_csv(io.BytesIO(csv3)).to_dict()) | |
# res = make_response('<html><head><title>JBoss - Error report</title></head></html>', {'Content-Type': 'text/html', 'Access-Control-Allow-Origin': '*'}) | |
res = make_response(pd.read_csv(io.BytesIO(raw_csv)).to_html(), {'Content-Type': 'text/html', 'Access-Control-Allow-Origin': '*'}) | |
print(f'res: {res}, type res: {type(res)}') | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment