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