FittsLaw/utils/server.py
2020-05-15 23:42:44 -04:00

52 lines
1.6 KiB
Python

from flask import Flask, jsonify, request
import json
import os
app = Flask(__name__)
base = os.getcwd()
help = 'WW91IGZvdW5kIHRoZSBzZWNyZXQgbGlmZWxpbmUhIEdvb2QgZm9yIHlvdS4gWW91J3JlIHByb2JhYmx5IGZpbmUsIGJ1dCBpZiB5b3UgbmVlZCBoZWxwIHdpdGggc29tZXRoaW5nIG5vIG9uZSBlbHNlIHVuZGVyc3RhbmRzLCBlbWFpbCBmaXR0c0BzdXBlcnBpY2h1Lm9yZy4KUGxlYXNlIGtlZXAgdGhlIGV4aXN0ZW5jZSBvZiB0aGlzIHRvIHlvdXJzZWxmLiBOb2JvZHkgbGlrZXMgYSBuYXJjLg=='
@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)