Skip to content

Commit 3a01c07

Browse files
author
Steven Pousty
committed
new code
1 parent 144196b commit 3a01c07

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

1_app.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
__author__ = 'spousty'
2+
3+
from bottle import route, run, DEBUG
4+
import os
5+
6+
7+
8+
@route('/')
9+
def index():
10+
return "<h1> hello OpenShift Ninja without DB</h1>"
11+
12+
if __name__ == '__main__':
13+
run(host='0.0.0.0', port=8080, debug=True)

app.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__author__ = 'spousty'
22

3-
#import psycopg2
4-
from bottle import route, run, DEBUG
3+
import psycopg2
4+
from bottle import route, run, get, DEBUG
55
import os
66

77

@@ -10,24 +10,25 @@
1010
def index():
1111
return "<h1> hello OpenShift Ninja without DB</h1>"
1212

13-
#@route('/db')
14-
#def dbexample():
15-
# print(os.environ.get('POSTGRESQL_USER'))
16-
# print("After Env")
17-
# try:
18-
# conn = psycopg2.connect(database='db', user=os.environ.get('POSTGRESQL_USER'), host=os.environ.get('POSTGRESQL_92_CENTOS7_SERVICE_HOST'), password=os.environ.get('POSTGRESQL_PASSWORD'))
19-
# except:
20-
# print( os.environ.get('POSTGRESQL_USER') + " " + os.environ.get('POSTGRESQL_92_CENTOS7_SERVICE_HOST'))
13+
# since this is a read only talk to the replicas
14+
@get('/db')
15+
def dbexample():
16+
print(os.environ.get('POSTGRESQL_USER'))
17+
print("After Env")
18+
try:
19+
conn = psycopg2.connect(database='db', user=os.environ.get('POSTGRESQL_USER'), host=os.environ.get('POSTGRESQL_92_CENTOS7_SERVICE_HOST'), password=os.environ.get('POSTGRESQL_PASSWORD'))
20+
except:
21+
print( os.environ.get('POSTGRESQL_USER') + " " + os.environ.get('POSTGRESQL_92_CENTOS7_SERVICE_HOST'))
2122

22-
# cur = conn.cursor()
23-
# cur.execute("""SELECT * from pg_user""")
23+
cur = conn.cursor()
24+
cur.execute("""SELECT * from pg_user""")
2425

25-
# rows = cur.fetchall()
26-
# result_string = "<h2>Here are your results: </h2>"
27-
# for row in rows:
28-
# result_string += "<h3>" + row[0] + "</h3>"
29-
#
30-
# return result_string
26+
rows = cur.fetchall()
27+
result_string = "<h2>Here are your results: </h2>"
28+
for row in rows:
29+
result_string += "<h3>" + row[0] + "</h3>"
30+
31+
return result_string
3132

3233
if __name__ == '__main__':
3334
run(host='0.0.0.0', port=8080, debug=True)

0 commit comments

Comments
 (0)