-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapp.py
55 lines (48 loc) · 1.35 KB
/
app.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from flask import Flask, render_template
from flask import jsonify
import socket
app = Flask(__name__)
# two decorators, same function
@app.route('/')
@app.route('/index.html')
def index():
return render_template('index.html', the_title='Tiger Home Page')
@app.route('/symbol.html')
def symbol():
return render_template('symbol.html', the_title='Tiger As Symbol')
@app.route('/myth.html')
def myth():
return render_template('myth.html', the_title='Tiger in Myth and Legend')
@app.route('/ip')
def ip():
hostname = socket.gethostname()
IPAddr = socket.gethostbyname(hostname)
d = {
"hostname": hostname,
"IPAddr": IPAddr,
}
return jsonify(d)
@app.route('/test-mysql-db-connection')
def test_db_connection():
try:
# google sql cloud database -- ip whitelisting test for heroku app
from mysql.connector import connect
cnx = connect(
host='35.238.34.27',
database='demo',
user='nivratti',
password='nivpoijkldfghcc@@',
port=3306
)
d = {
"success": True,
"message": "Connected to database successfully",
}
except Exception as e:
d = {
"success": False,
"message": str(e),
}
return jsonify(d)
if __name__ == '__main__':
app.run(debug=True)