-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
27 lines (23 loc) · 790 Bytes
/
app.py
File metadata and controls
27 lines (23 loc) · 790 Bytes
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
from flask import Flask
from flask import request
import psycopg2
import sys
con = psycopg2.connect(host='postgres', port='5432', database='postgres', user='postgres', password='secret')
cur = con.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS reverse (input VARCHAR(255), output VARCHAR(255))")
con.commit()
app = Flask(__name__)
@app.route("/reverse", methods = ["POST"])
def reverse():
reverse = request.get_data()[::-1]
cur = con.cursor()
cur.execute("INSERT INTO reverse VALUES ('" + request.get_data() + "', '" + reverse + "')")
con.commit()
return reverse
@app.route("/cache", methods = ["GET"])
def get():
cur = con.cursor()
cur.execute('SELECT * FROM reverse')
return str(cur.fetchall())
if __name__ == "__main__":
app.run(host='0.0.0.0')