-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
36 lines (29 loc) · 949 Bytes
/
main.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
#!env/bin/python
import os
from flask import Flask, render_template
import MySQLdb
app = Flask(__name__)
app.debug = True
@app.route("/")
def index():
HIT_COUNTER_PATH = "/var/number.txt"
# if no hit count exists, create one
if not os.path.exists(HIT_COUNTER_PATH):
with open(HIT_COUNTER_PATH, "w") as f:
f.write("0\n")
# load hit count
hit_count = None
with open(HIT_COUNTER_PATH) as f:
hit_count = int(f.read().strip(), 10)
hit_count += 1 # increment hit count
# save hit count
with open(HIT_COUNTER_PATH, "w") as f:
f.write(str(hit_count) + '\n')
# Test database connection
conn = MySQLdb.connect(host='localhost', user='root', passwd="")
curs = conn.cursor()
curs.execute("SELECT 1 + 1")
dbresult = curs.fetchone()
return render_template("index.html", hit_count=hit_count, dbresult=dbresult)
application = app.wsgi_app
print("Prepared.")