Created
December 2, 2020 20:52
-
-
Save CrashLaker/6578dfb70d5d0cbaeeb82f0058e129d3 to your computer and use it in GitHub Desktop.
medium-grafana-simplejson-query-ec2info
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 dateutil.parser | |
import requests | |
from bs4 import BeautifulSoup | |
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(): | |
rs = requests.get("https://www.ec2instances.info") | |
html = BeautifulSoup(rs.content, 'html.parser') | |
table = html.find('table') | |
tt = str(table) | |
df = pd.read_html(tt)[0] | |
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