-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
executable file
·45 lines (36 loc) · 975 Bytes
/
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
#!/usr/bin/env python
import os
import bottle_mysql
from bottle import Bottle
from bottle import HTTPError
from bottle import run
from bottle import static_file
DBUSER = os.environ.get("DBUSER")
DBPASS = os.environ.get("DBPASS")
DBNAME = os.environ.get("DBNAME")
DBHOST = os.environ.get("DBHOST")
DBPORT = int(os.environ.get("DBPORT"))
app = Bottle()
plugin = bottle_mysql.Plugin(
# overwrite with this for a local setup:
# dbuser="user", dbpass="pass", dbname="db",
# dbhost="127.0.0.1", dbport=6446
dbuser=DBUSER,
dbpass=DBPASS,
dbname=DBNAME,
dbhost=DBHOST,
dbport=DBPORT,
)
app.install(plugin)
@app.route("/show")
def show(db):
db.execute("SELECT * FROM user")
row = db.fetchone()
if row:
return row
return HTTPError(404, "Page not found")
@app.route("/favicon.ico")
def favicon():
"""Sends the favicon.ico file."""
return static_file("favicon.ico", root=".")
run(app, host="0.0.0.0", port=8080)