-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
59 lines (51 loc) · 1.59 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import json
from flask import Flask, render_template, request, redirect, make_response, send_from_directory
import database
with open('secret.txt','r',encoding='utf-8') as f:
secret = f.readline()
app = Flask(__name__)
@app.route("/")
def index():
return app.send_static_file("html/main.html")
@app.route("/ping",methods=["GET","POST"])
def ping():
try:
data = request.get_json()
print(data)
except:
print("Pas de donnée dans la request")
return "pong"
@app.route("/get_mri",methods=["GET","POST"])
def get_mri():
mris=database.get_mris()
result_list=[database.cleanResult(mri) for mri in mris]
result_json=json.dumps(result_list[::-1])
return result_json
@app.route('/new',methods=["POST"])
def new_mri():
try:
data = request.get_json()
if data["secret"] != secret:
print("Erreur de secret")
return "Unauthorized"
print("Accepté")
database.insert_mri(data["body"])
except Exception as e:
print(e)
print("Pas de donnée dans la request")
return "Error"
return "OK"
@app.route("/view/<identifier>",methods=["GET"])
def view(identifier):
try:
mri = database.getMri(identifier)
if mri=="":
return app.redirect("/",404)
return render_template("view.html",html=mri['mri'],title=mri['title'])
except:
return app.redirect("/",404)
if __name__ == '__main__':
app.run(debug=False,port=8080,host="0.0.0.0") #Lance l'application
@app.route("/favicon.ico")
def favicon():
return app.send_static_file("favicon.ico")