from flask import Flask, jsonify, request import json import os app = Flask(__name__) base = os.getcwd() @app.route('/cardboard') def card(): data = json.load(open(base + '/cardTrials.json')) return jsonify(data) @app.route('/cardboardPost', methods=['POST']) def cardPost(): id = int(request.args.get('id', '')) data = json.load(open(base + '/cardTrials.json')) data['participantId'] = id json.dump(data,open(base + '/cardTrials.json','w')) return 'ok ' + str(id) @app.route('/oculus') def oculus(): data = json.load(open(base + '/oculusTrials.json')) return jsonify(data) @app.route('/oculusPost',methods=['POST']) def oculusPost(): id = int(request.args.get('id', '')) data = json.load(open(base + '/oculusTrials.json')) data['participantId'] = id json.dump(data,open(base + '/oculusTrials.json','w')) return 'ok ' + str(id) @app.route('/mouse') def mouse(): data = json.load(open(base + '/mouseTrials.json')) return jsonify(data) @app.route('/mousePost',methods=['POST']) def mousePost(): id = int(request.args.get('id', '')) data = json.load(open(base + '/mouseTrials.json')) data['participantId'] = id json.dump(data,open(base + '/mouseTrials.json','w')) return 'ok ' + str(id) if __name__ == '__main__': app.debug = False app.run(host = '0.0.0.0',port=5000)