-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
39 lines (32 loc) · 1.01 KB
/
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
from flask import Flask, request, Response
from flask_cors import CORS
import json
app = Flask(__name__)
CORS(app)
url = "/control/"
@app.route(url+"hello")
def hello_world():
print("in hello")
return "blabla"
@app.route(url+"add_group", methods=["POST"])
def add_group():
print("in add group")
json_req = request.get_json()
print("----- " + str(json_req) + " -----")
groups = read_groups()
groups.append(json_req)
print("----- " + str(groups) + " -----")
with open("/home/henrik/workspace/jf/voelkerball-python/groups", "w") as file:
json.dump(groups, file)
return "", 204
@app.route(url+"get_groups", methods=["GET"])
def get_groups():
print("in get groups")
groups = read_groups()
print("----- " + str(groups) + " -----")
return Response(json.dumps(groups), mimetype="application/json")
def read_groups():
with open("/home/henrik/workspace/jf/voelkerball-python/groups", "r") as file:
groups = json.load(file)
return groups
return ""