def bookParkingSpot(self, data): if "serial_number" in data and "email" in data: devicedb = self.db.devicedata time = datetime.datetime.now().strftime("%H:%M:%S") record = dumps( devicedb.update({"serial_number": data["serial_number"]}, { '$set': { 'booked': data['email'], 'booked_start_time': time, 'rate': 5 } }, False, True)) record = json.loads(record) print(record) if record['updatedExisting'] == True: record = dumps( devicedb.find_one({"serial_number": data["serial_number"]})) record = json.loads(record) return json.dumps({ "status": "success", "message": { "serial_number": record['serial_number'], 'name': record['name'], 'lat': record['lat'], 'long': record['long'], 'owner': record['owner'], 'booked_start_time': record['booked_start_time'] } }) else: return Codes.invalidDevice() else: return Codes.badRequest()
def endBooking(self, data): if 'serial_number' in data: devicedb = self.db.devicedata end_time = datetime.datetime.now().strftime("%H:%M:%S") record = dumps( devicedb.find_one({"serial_number": data["serial_number"]})) record = json.loads(record) print(record['booked']) if record is None: return Codes.invalidDevice() else: parked_time = int(end_time[0:2]) - int( record['booked_start_time'][0:2]) amount = (1 + parked_time) * 10 self.addMoney({"email": record["owner"], "amount": amount}) self.deductMoney(({ "email": record["booked"], "amount": amount })) record = dumps( devicedb.update({"serial_number": record["serial_number"]}, { "$set": { "booked_start_time": "00", "booked": "false" } }, False, True)) record = json.loads(record) if record['updatedExisting'] == True: return json.dumps({ "status": "success", "message": { "amount": amount } }) else: return Codes.invalidDevice() else: return Codes.badRequest()
def registerDevice(self, data): devicedb = self.db.devicedata if 'serial_number' in data and 'name' in data and 'lat' in data and 'long' in data and 'owner' in data and 'address' in data: record = dumps( devicedb.find_one({'serial_number': data['serial_number']})) record = json.loads(record) if record is None: return Codes.invalidDevice() else: record = dumps( devicedb.update({"serial_number": data["serial_number"]}, { '$set': { 'name': data['name'], 'lat': data['lat'], 'long': data['long'], 'owner': data['owner'], 'address': data['address'] } }, False, True)) record = json.loads(record) print(record) if record['updatedExisting'] == True: return json.dumps({ "status": "success", "message": { "serial_number": data["serial_number"], 'name': data['name'], 'lat': data['lat'], 'long': data['long'], 'owner': data['owner'], 'address': data['address'] } }) else: return Codes.invalidDevice() else: return Codes.badRequest()
def getDeviceData(self, data): if 'serial_number' in data: devicedb = self.db.devicedata record = dumps( devicedb.find_one({"serial_number": data["serial_number"]})) record = json.loads(record) print(record) if record is None: return Codes.invalidDevice() else: return json.dumps({ "status": "success", "message": { "serial_number": record['serial_number'], "status": record["status"], "booked": record["booked"] } }) else: return Codes.badRequest()