-
Notifications
You must be signed in to change notification settings - Fork 93
/
main.py
54 lines (39 loc) · 991 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import base64
import sqlite3
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def home():
conn = sqlite3.connect('my_database.db')
c = conn.cursor()
if request.method == 'POST':
transaction = "INSERT INTO messages VALUES ('{}', '{}')".format(
request.remote_addr,
request.form['content'],
)
c.execute(transaction)
conn.commit()
body = """
<html>
<body>
<h1>Messages</h1>
<h2>Enter a Message</h2>
<form method="POST">
<label for="content">Message</label>
<input type="text" name="content"><br>
<input type="submit" value="Submit">
</form>
<h2>Messages</h2>
"""
for m in c.execute("SELECT * FROM messages"):
body += """
<div class="message">
{}: {}
</div>
""".format(m[0], m[1])
c.close()
return body
if __name__ == "__main__":
port = int(os.environ.get("PORT", 6779))
app.run(host='0.0.0.0', port=port)