def addVehicle(): if request.method == 'POST': from backend.models.Response import parkingResponse #removed logging from this function as it is the primary call and will be logged a lot of times response.content_type = 'application/json' from backend.controllers.VehicleController import VehicleController cstHand = VehicleController() try: postJson = json.load(request.body) obj = mngParking.getParkingDetaisByLotId(postJson["lotId"]) logging.info("here i amj") logging.info(obj) if (postJson["vehicleType"] == "two"): if (obj["twoWheelerParkingCount"] - obj["twoWheelerOccupied"]) > 0: mngParking.updateParkingLot("two", postJson["lotId"]) if (postJson["vehicleType"] == "lmv"): if (obj["lMVParkingCount"] - obj["lMVOccupied"]) > 0: mngParking.updateParkingLot("lmv", postJson["lotId"]) logging.info("The data posted is %s" % postJson) postResponse = cstHand.add_vehicle_at_lot(postJson) return postResponse except: logging.exception( "Some error occurred while trying to create parking") res = parkingResponse() failure = res.getFailureResponse() failure.status.message = 'Error during parking' return failure.to_JSON()
def FreePort(): if 'skip' not in sys.argv: logging.info("Trying to Kill process on port %s"%PORT) try: os.popen("kill -9 $(lsof -i :8081 | grep 'Python' | awk '{print $2}' )") pass except : logging.exception('Unable to free the port')
def main(): logging.debug("Inside Main Run Api Server. Trying to start the API server") #port = int(os.environ.get("PORT", PORT)) try: run(app, host='0.0.0.0', port=PORT, reloader=True) logging.info("baba") except: logging.exception("An error occurred while trying to start the API server")
def getRecentCustomers(): from backend.controllers.ParkingController import ParkingController logging.debug("/parkings GET called") cstHand = ParkingController() try: postJson = cstHand.response_parking() logging.debug('sending %s' % (postJson)) except ValueError: logging.exception( "Some error occurred while trying to get customer count") response.content_type = 'application/json' #post json response received from function is already serialized return postJson
def add_parking_lot(self, jsonData): res = parkingResponse() try: status = addParkingLot(jsonData) if status: success = res.getSuccessResponse() success.status.message = 'data posted successfully' return success.to_JSON() except: logging.exception("Unable to post parking lot to DB") failure = res.getFailureResponse() failure.status.message = 'unable to post data' logging.info("parking lot post to DB of FFC failed") return failure.to_JSON()
def TestMode(): from backend.controllers.TestModeController import TestModeController response.content_type = 'application/json' logging.info("Test mode API called") res = parkingResponse() try: if request.query.get("command"): if any(word in request.query.get("command") for word in ["start", "stop", "status", "pause"]): logging.info("test command is %s" % request.query.get("command")) tbobj = TestModeController(request.query.get("command")) responsejson = tbobj.ProcessTestModeCommand() return responsejson except: logging.exception("Unable to process request failed") failure = res.getFailureResponse() failure.status.message = "Unable to process request, command not valid" return failure.to_JSON()
def addParkingLot(): if request.method == 'POST': from backend.models.Response import parkingResponse #removed logging from this function as it is the primary call and will be logged a lot of times response.content_type = 'application/json' from backend.controllers.ParkingController import ParkingController cstHand = ParkingController() try: postJson = json.load(request.body) logging.info("The data posted is %s" % postJson) postResponse = cstHand.add_parking_lot(postJson) return postResponse except: logging.exception( "Some error occurred while trying to create parking lot") res = parkingResponse() failure = res.getFailureResponse() failure.status.message = 'Error during creating parking lot' return failure.to_JSON()
def removeVehicle(): if request.method == 'GET': from backend.models.Response import parkingResponse logging.info("remove") #removed logging from this function as it is the primary call and will be logged a lot of times response.content_type = 'application/json' vehicleId = request.query.get("vehicleid") try: logging.info("v id is %s" % vehicleId) obj = mngParking.getVechileDetaisl(vehicleId) logging.info(obj) objLot = mngParking.getParkingDetaisByLotId(obj.lotId) logging.info(obj) if (obj.vehicleType == "two"): rate = objLot["twoWheelerParkingPrice"] mngParking.updateRemoveParkingLot("two", obj.lotId) if (obj.vehicleType == "lmv"): rate = objLot["lMVParkingPrice"] mngParking.updateRemoveParkingLot("lmv", obj.lotId) TimeStart = obj.insert_time now = datetime.datetime.now() logging.info(TimeStart) logging.info((now - TimeStart).total_seconds()) delatTime = (now - TimeStart).total_seconds() logging.info(rate) return { "cost": (int)(delatTime / (60 * 60)) * rate, "vehicleid": vehicleId, "duration": (delatTime) / (60 * 60) } except: logging.exception( "Some error occurred while trying to create parking") res = parkingResponse() failure = res.getFailureResponse() failure.status.message = 'Error during removing' return failure.to_JSON()
def response_parking(self): res = parkingResponse() logging.info("response customer controller") try: data = getParking() except: logging.exception("Error Unable to get customers") failure = res.getFailureResponse() failure.status.message = 'get Parking fail' return failure.to_JSON() success = res.getSuccessResponse() if data: # for row in data: # time = datetime.fromtimestamp(row['eventTime']) # row['eventTime'] = str(time) logging.info("get Parking FFC %s" % data) success.response = data else: success.status.message = 'customer count empty' logging.info("get Parking FFC empty data: %s" % data) return success.to_JSON()
logging.info( "Error occurred while trying to convert JSON to xml. Incorrect usage.") def main(): root = None if len(sys.argv[1:]): try: (opts, args) = getopt.getopt(sys.argv[1:], 'r:', ['root']) if (len(args)): raise getopt.GetoptError('bad parameter') except getopt.GetoptError: usage() sys.exit(0) for (opt, arg) in opts: if opt in ('-r', '--root'): root = arg parse_json_stdin(root) if __name__ == '__main__': try: main() except: logging.exception( "An error occurred while trying to convert JSON to XML")