jcramalho

exemplo1-flask

Apr 26th, 2021
792
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | None | 0 0
  1. from flask import Flask
  2. import requests
  3.  
  4. app = Flask(__name__)
  5.  
  6. @app.route("/")
  7. def index():
  8.     html = """
  9.    <html>
  10.      <head>
  11.        <title>My first Python Web App</title>
  12.        <meta charset="utf8"/>
  13.      </head>
  14.      <body>
  15.        <h3>Operações disponíveis:</h3>
  16.        <ul>
  17.            <li><a href="/entidades">Lista de Entidades</a></li>
  18.            <li><a href="/classesN3">Lista de Processos de Negócio</a></li>
  19.        </ul>
  20.      </body>
  21.    </html>
  22.    """
  23.     return html
  24.  
  25.  
  26. @app.route("/entidades")
  27. def entidades():
  28.     apikey = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYwODE4ODU1YTcxOGRmNGVkMTkwZjE1ZSIsImlhdCI6MTYxOTEwMTc4MSwiZXhwIjoxNjIxNjkzNzgxfQ.SlyayNaXu8PTPYAtyR9h7tIlR9ooXn72DRn6EAwcgV6rNY1rZQCoSs_d2EESIJs3kb0LwCSfU9o5lWMW9_Twigj3FxX99iAg7_gB1m6TReJ2moZ-rYIst6RTtJtWQWBezZ-37RyACH9s44WQ9qnlrXBYKgnW6LyVi18KdfwEYekgbKM6bSkvPTVYdtjkzktKwKZfIouts4nQGm0tvTfQC_AtOP22338i5N2I952gBN0lf9fn6iaj64TCAXaUA4JhMNZad6ekK0AWauGZsHcaOaLiqpbxKjGs2d69fCOcdKsbDGwoGSEL_6TUho9Yfb405yS9ZE4TjatGNtBaRmSv9g"
  29.     r = requests.get('http://clav-api.di.uminho.pt/v2/entidades?apikey=' + apikey)
  30.     entidades = r.json()
  31.  
  32.     html = """
  33.    <html>
  34.      <head>
  35.        <title>My first Python Web App</title>
  36.        <meta charset="utf8"/>
  37.      </head>
  38.      <body>
  39.        <h3>Lista de Entidades</h3>
  40.        <table>
  41.          <tr>
  42.            <th>Sigla</th><th>Designação</th><th>Id</id>
  43.          </tr>
  44.    """
  45.     for e in entidades:
  46.         html += f"""
  47.        <tr><td>{e['sigla']}</td><td>{e['designacao']}</td><td>{e['id']}</td></tr>
  48.        """
  49.  
  50.     html +="""
  51.        </table>
  52.      </body>
  53.    </html>
  54.    """
  55.     return html
  56.  
  57. @app.route("/classesN3")
  58. def classesN3():
  59.     return "<h3>Esta é para tu fazeres...</h3>"
  60.  
  61. if __name__ == "__main__":
  62.     app.run(host="0.0.0.0", port=3026)
  63.  
  64.      
  65.  
Advertisement
Add Comment
Please, Sign In to add comment