-
Notifications
You must be signed in to change notification settings - Fork 310
/
2_app.py
38 lines (27 loc) · 1.09 KB
/
2_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
__author__ = 'spousty'
import psycopg2
from bottle import route, run, get, DEBUG
import os
@route('/')
def index():
return "<h1> hello OpenShift Ninja without DB</h1>"
# since this is a read only talk to the replicas
@get('/db')
def dbexample():
try:
conn = psycopg2.connect(database=os.environ.get('PG_DATABASE'), user=os.environ.get('PG_USER'),
host=os.environ.get('REPLICA_SERVICE_HOST'), password=os.environ.get('PG_PASSWORD'))
except:
print(os.environ.get('REPLICA_SERVICE_HOST'))
cur = conn.cursor()
# cur.execute("""select parkid, name, ST_AsText(the_geom) from parkpoints limit 10""")
cur.execute("""select parkid, name, ST_AsText(the_geom) from parkpoints ORDER by parkid DESC LIMIT 10""")
rows = cur.fetchall()
result_string = "<h2>Here are your results: </h2>"
for row in rows:
result_string += "<h3>" + str(row[0]) + ", " + str(row[1]) + ", " + str(row[2]) + "</h3>"
cur.close()
conn.close()
return result_string
if __name__ == '__main__':
run(host='0.0.0.0', port=8080, debug=True)