FittsLaw/utils/server.py

52 lines
1.6 KiB
Python
Raw Normal View History

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