def parseJSONRequest(req): request = req["request"] if request == "location": aps = req["aps"] try: return AccessPoints.computeLocation(aps) except NotFoundException: raise if request == "freeroom": building = req["building"] floor = req.get("floor") stime = req.get("starttime") etime = req.get("endtime") try: return findFreeRoom(building,floor,stime,etime) except NotFoundException: raise
def jsonRequest(): if request.method == "POST": try: if request.json != None: print "Received JSON request: ", request.json try: req = Controller.parseJSONRequest(request.json) return resultOkay(req) except NotFoundException as e: return resultError(e.getError()) except ValueError as e: return resultError("Input malformed:" + str(e)) # except: # return resultError("Either Input or output malformed") else: return resultError("Input malformed: You didn't send the request with application/json") except: return resultError("JSON malformed...") else: return """<pre>Expecting application/json via HTTP POST</pre>""" if __name__ == "__main__": Model.init() AccessPoints.read() # AccessPoints.read() # print getAccessPoint("00:0f:61:b4:b6:00") # Cache.cache(Building.findRoom("HG","F","5")) # print getRoom("HG","F","5") app.run(port=config.SERVER_PORT, host="0.0.0.0", debug=True)