forked from iuliana-cergedean/pythoncode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
36 lines (30 loc) · 867 Bytes
/
app.py
File metadata and controls
36 lines (30 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# My microservice!
import requests
from flask import Flask
from flask import render_template
from flask_sqlalchemy import SQLAlchemy
from config import Configuration
# create Flask app
app = Flask(__name__)
app.config.from_object(Configuration)
db = SQLAlchemy(app)
# GET request to ip.jsontest.com
def home():
return render_template('home.html')
def rest_request_example():
print (requests.get("http://ip.jsontest.com/").text)
def read_db_SQL_example():
conn = db.get_engine().connect()
sql = "SELECT * FROM SampleTable"
results = conn.execute(sql)
rows = ""
for row in results:
rows = rows + ','.join(row) + "<br/>"
print(rows)
rest_request_example()
try:
read_db_SQL_example()
except:
print ('Could not connect to database')
if __name__ == '__main__':
app.run(host=app.config['HOST'], port=app.config['PORT'])