Created
December 2, 2020 21:27
-
-
Save CrashLaker/29afbadbf2962094d2d4d4df848e8548 to your computer and use it in GitHub Desktop.
medium-grafana-simplejson-ec2info-csv
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, request, jsonify | |
from flask_cors import CORS | |
import pandas as pd | |
app = Flask(__name__) | |
cors = CORS(app) | |
@app.route('/', methods=['GET', 'POST']) | |
def main(): | |
return "você acessou o /" | |
@app.route('/search', methods=['GET', 'POST']) | |
def r_search(): | |
return "você acessou o /search" | |
@app.route('/query', methods=['GET', 'POST']) | |
def r_query(): | |
df = pd.read_csv("./AWS-EC2.csv") | |
#df = pd.read_csv("http://exemplo.com/arquivo/AWS-EC2.csv") pode ser URL | |
df = df[["Name", "API Name", "Memory", "vCPUs", "Instance Storage"]] | |
data = df.to_dict(orient='split') | |
response = [ | |
{ | |
"columns":[ | |
{"text": c, "type": "string"} | |
for c in data["columns"] | |
], | |
"rows":data["data"], | |
"type":"table" | |
}, | |
] | |
return jsonify(response) | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=8081) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment