def flaskUpdateStatus(): filename = "/Users/niels/Sites/getStatus" reply = getStatus.getStatus(1) f = open(filename,"w") if not reply == None and len(reply) == 3: f.write("""{{"scenario": {0}, "threshold": {1}, "lightsensor": {2}, "lamp_on": {3}}}""".format(1, reply[0], reply[1], reply[2])) elif not reply == None and len(reply) == 4: f.write("""{{"scenario": {0}, "threshold": {1}, "lightsensor": {2}, "lamp_on": {3}, "occupied": {4}}}""".format(2, reply[0], reply[1], reply[2], reply[3])) else: print "=====FAIL======" print reply f.close() f = open(filename,"r") print f.readlines() f.close() return "OK"
def flaskGetStatus(): # return jsonify(scenario=1, # threshold=21, # lightsensor=22, # lamp_on=0) reply = getStatus.getStatus(1) if reply == None: print "Fail!" elif len(reply) == 3: return """{{"scenario": {0}, "threshold": {1}, "lightsensor": {2}, "lamp_on": {3}}}""".format(1, reply[0], reply[1], reply[2]) else: return """{{"scenario": {0}, "threshold": {1}, "lightsensor": {2}, "lamp_on": {3} "occupied": {4}}}""".format(2, reply[0], reply[1], reply[2], reply[3])