Exemplo n.º 1
0
    def post(self):
        if User_tool.check_before_start("updatePosition", self) >= 0:
            data = json.loads(self.request.body)
            latitude = data["Latitude"]
            longitude = data["Longitude"]
            id_car = data["ID_car"]
            try:
                Car.update_position_ID(id_car, latitude, longitude)

                # push_class.send_post_request("APA91bFKpc1XNokg3Gv9GTWI49oE-UXe-ED6JMam2YPdAYG23yJf_P3c7Tl_55f9iECuhSNVa86PfZfcZ4knQ2VzFuBy_lNrq5_DLRHcghMkTQtRl9jyCbL6tV5TquDrse-dMQlGx9HKDLbtCNwEhGEFVeWXQH9EBjCt-VewSitHtgk2BxIB-w20ZLZtz2MCGAqRnTKD8B5n")

                temp_car_group = Car_group.getGroupFromCar(long(id_car))
                for group_result in temp_car_group:
                    list_user = User_group.getUserFromGroup(group_result.id_group)
                    result_id_android = []
                    for user_result in list_user:
                        temp_user = User.get_user_by_id(user_result.id_user)
                        if temp_user.email != data["Email"]:
                            if temp_user.is_user == 1:
                                logging.debug("Indirizzo email utente del push: " + str(temp_user.email))
                                result_id_android.append(temp_user.id_android)
                                # push_class.send_push_park(temp_user.id_android)
                            else:
                                Send_email.send_position(temp_user.email, latitude, longitude)
                    if len(result_id_android) > 0:
                        push_class.send_push_park(result_id_android , Car.get_name_id(long(id_car)))

                right = StatusReturn(5, "updatePosition")
                self.response.write(right.print_result())
            except:
                self.error(500)
                error = StatusReturn(8, "updatePosition", str(sys.exc_info()))
                self.response.write(error.print_general_error())
Exemplo n.º 2
0
    def post(self):
        if User_tool.check_before_start("editCar", self) >= 0:

            dati = json.loads(self.request.body)

            car_data = dati["Car"]
            bluetooth_MAC = ""
            bluetooth_name = ""
            register = ""
            maker_color = None
            if "Bluetooth_MAC" in car_data:
                bluetooth_MAC = car_data["Bluetooth_MAC"]
            if "Bluetooth_Name" in car_data:
                bluetooth_name = car_data["Bluetooth_Name"]
            if "Register" in car_data:
                register = car_data["Register"]
            if "Marker_Color" in car_data:
                maker_color = car_data["Marker_Color"]

            Car.update_car(car_data["ID_car"], bluetooth_MAC, bluetooth_name,
                           car_data["Brand"], car_data["Name"], register,
                           maker_color)

            right = StatusReturn(19, "editCar")
            self.response.write(right.print_result())
Exemplo n.º 3
0
    def post(self):
        if User_tool.check_before_start("updatePosition", self) >= 0:
            dati = json.loads(self.request.body)

            car_data = dati["Car"]
            Car.pick_car(car_data["ID_car"])

            right = StatusReturn(22, "pickCar", False)
            self.response.write(right.print_result())
Exemplo n.º 4
0
    def post(self):
        if User_tool.check_before_start("updatePosition", self) >= 0:
            dati = json.loads(self.request.body)

            car_data = dati["Car"]
            Car.pick_car(car_data["ID_car"])

            right = StatusReturn(22, "pickCar", False)
            self.response.write(right.print_result())
Exemplo n.º 5
0
    def post(self):
        if User_tool.check_before_start("getCars", self) >= 0:

            dati = json.loads(self.request.body)

            if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS:
                logging.debug(dati)

            user_data = dati["User"]
            lower_email = user_data["Email"].lower()
            temp_user = User.static_querySearch_email(lower_email)

            if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS:
                logging.debug(temp_user)

            id_user = temp_user.get()

            if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS:
                logging.debug(id_user.key.id())

            cars = User_car.getCarFromUser(id_user.key.id())

            if (cars.count() == 0):
                allcars = []
                right = StatusReturn(3, "getAllCars_fromEmail", allcars)
                self.response.write(right.print_result())
            else:
                allcars = []
                for id_carTemp in cars:
                    if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS:
                        logging.debug(id_carTemp)
                    allcars.append(Car.get_json(long(id_carTemp.id_car)))

                right = StatusReturn(3, "getCars", allcars)
                self.response.write(right.print_result())
Exemplo n.º 6
0
    def post(self):
        if User_tool.check_before_start("getCars", self) >= 0:

            dati = json.loads(self.request.body)

            if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS:
                logging.debug(dati)

            user_data = dati["User"]
            lower_email = user_data["Email"].lower()
            temp_user = User.static_querySearch_email(lower_email)

            if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS:
                logging.debug(temp_user)

            id_user = temp_user.get()

            if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS:
                logging.debug(id_user.key.id())

            cars = User_car.getCarFromUser(id_user.key.id())

            if (cars.count() == 0):
                allcars = []
                right = StatusReturn(3, "getAllCars_fromEmail", allcars)
                self.response.write(right.print_result())
            else:
                allcars = []
                for id_carTemp in cars:
                    if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS:
                        logging.debug(id_carTemp)
                    allcars.append(Car.get_json(long(id_carTemp.id_car)))

                right = StatusReturn(3, "getCars", allcars)
                self.response.write(right.print_result())
Exemplo n.º 7
0
    def post(self):
        if User_tool.check_before_start("updatePosition", self) >= 0:
            dati = json.loads(self.request.body)
            user_data = dati["User"]
            temp_user = User.static_querySearch_email(user_data["Email"])

            car_data = dati["Car"]

            timestamp = str(datetime.datetime.utcnow() +
                            datetime.timedelta(hours=1))
            if "Timestamp" in car_data:
                timestamp = car_data["Timestamp"]

            Car.update_position_ID(car_data["ID_car"], car_data["Latitude"],
                                   car_data["Longitude"], user_data["Email"])

            list_user = User_car.getUserFromCar(car_data["ID_car"])

            # Send notification to all user register with this car
            for user in list_user:

                # If the user is not registered inside the application send him an email
                if User.is_registered_check(user.id_user) == 0:
                    if User.get_email_user(user.id_user) != user_data["Email"]:
                        # Send_email.send_position(User.get_email_user(user.id_user), car_data["Latitude"],
                        #                      car_data["Longitude"], user_data["Name"],car_data["Name"])
                        logging.debug("Update position")
                else:
                    if User.get_email_user(user.id_user) != user_data["Email"]:
                        Push_notification.send_push_park(
                            User.get_id_android(user.id_user),
                            car_data["Name"], user_data["Name"],
                            car_data["ID_car"])

            if static_variable.DEBUG:
                logging.debug("Date if car: " + car_data["Name"])

            id_user = temp_user.get().key.id()

            if static_variable.DEBUG:
                logging.debug(timestamp)

            History_park.update_history(id_user, car_data["Latitude"],
                                        car_data["Longitude"], timestamp)

            right = StatusReturn(5, "updatePosition")
            self.response.write(right.print_result())
Exemplo n.º 8
0
    def post(self):
        if User_tool.check_before_start("updateGCM", self) >= 0:

            dati = json.loads(self.request.body)
            car_data = dati["Car"]
            if Car.updateUUID(id=car_data["ID_car"], uuid=car_data["UUID"], bmaj=car_data["Bmaj"], bmin=car_data["Bmin"]) == 0:
                right = StatusReturn(15, "updateUUID")
                self.response.write(right.print_result())
Exemplo n.º 9
0
 def post(self):
     if User_tool.check_before_start("editCar", self) >= 0:
         data = json.loads(self.request.body)
         id = data["ID_car"]
         email = data["Email"]
         bluetooth_MAC = data["Bluetooth_MAC"]
         bluetooth_name = data["Bluetooth_name"]
         brand = data["Brand"]
         name = data["Name"]
         try:
             Car.update_car(id, bluetooth_MAC, bluetooth_name, brand, email, name)
             right = StatusReturn(16, "editCar")
             self.response.write(right.print_result())
         except:
             self.error(500)
             error = StatusReturn(8, "editCar", str(sys.exc_info()))
             self.response.write(error.print_general_error())
Exemplo n.º 10
0
    def post(self):
        if User_tool.check_before_start("updatePosition", self) >= 0:
            dati = json.loads(self.request.body)
            user_data = dati["User"]
            temp_user = User.static_querySearch_email(user_data["Email"])

            car_data = dati["Car"]

            timestamp = str(datetime.datetime.utcnow() + datetime.timedelta(hours=1))
            if "Timestamp" in car_data:
                timestamp = car_data["Timestamp"]

            Car.update_position_ID(car_data["ID_car"], car_data["Latitude"], car_data["Longitude"], user_data["Email"])

            list_user = User_car.getUserFromCar(car_data["ID_car"])

            # Send notification to all user register with this car
            for user in list_user:

                # If the user is not registered inside the application send him an email
                if User.is_registered_check(user.id_user) == 0:
                    if User.get_email_user(user.id_user) != user_data["Email"]:
                       # Send_email.send_position(User.get_email_user(user.id_user), car_data["Latitude"],
                       #                      car_data["Longitude"], user_data["Name"],car_data["Name"])
                        logging.debug("Update position")
                else:
                    if User.get_email_user(user.id_user) != user_data["Email"]:
                        Push_notification.send_push_park(User.get_id_android(user.id_user), car_data["Name"], user_data["Name"], car_data["ID_car"])

            if static_variable.DEBUG:
                logging.debug("Date if car: "+car_data["Name"])

            id_user = temp_user.get().key.id()



            if static_variable.DEBUG:
                logging.debug(timestamp)

            History_park.update_history(id_user,car_data["Latitude"],car_data["Longitude"], timestamp)

            right = StatusReturn(5, "updatePosition")
            self.response.write(right.print_result())
Exemplo n.º 11
0
    def post(self):
        if User_tool.check_before_start("getPositionCar", self) >= 0:
            data = json.loads(self.request.body)
            result = Car.get_position_id(data["ID"])
            result_JSON = {}
            result_JSON["latitude"] = result.latitude
            result_JSON["longitude"] = result.longitude

            right = StatusReturn(9, "getPositionCar", result_JSON)
            self.response.write(right.print_result())
Exemplo n.º 12
0
    def post(self):
        if User_tool.check_before_start("updateGCM", self) >= 0:

            dati = json.loads(self.request.body)
            car_data = dati["Car"]
            if Car.updateUUID(id=car_data["ID_car"],
                              uuid=car_data["UUID"],
                              bmaj=car_data["Bmaj"],
                              bmin=car_data["Bmin"]) == 0:
                right = StatusReturn(15, "updateUUID")
                self.response.write(right.print_result())
Exemplo n.º 13
0
    def post(self):
        if User_tool.check_before_start("deleteCar", self) >= 0:

            dati = json.loads(self.request.body)
            user_data = dati["User"]
            car_data = dati["Car"]

            temp_user = User.static_querySearch_email(user_data["Email"])
            user = temp_user.get()
            id_user = user.key.id()

            User_car.deleteCarUser(id_user, car_data["ID_car"])
            user_car = User_car.getUserFromCar(car_data["ID_car"])

            if static_variable.DEBUG:
                logging.debug("Number of car with this user: "******"ID_car"])

            right = StatusReturn(7, "deleteCar")
            self.response.write(right.print_result())
Exemplo n.º 14
0
    def post(self):
        if User_tool.check_before_start("deleteCar", self) >= 0:

            dati = json.loads(self.request.body)
            user_data = dati["User"]
            car_data = dati["Car"]

            temp_user = User.static_querySearch_email(user_data["Email"])
            user = temp_user.get()
            id_user = user.key.id()

            User_car.deleteCarUser(id_user, car_data["ID_car"])
            user_car = User_car.getUserFromCar(car_data["ID_car"])

            if static_variable.DEBUG:
                logging.debug("Number of car with this user: "******"ID_car"])

            right = StatusReturn(7, "deleteCar")
            self.response.write(right.print_result())
Exemplo n.º 15
0
    def post(self):
        if User_tool.check_before_start("editCar", self) >= 0:

            dati = json.loads(self.request.body)

            car_data = dati["Car"]
            bluetooth_MAC = ""
            bluetooth_name = ""
            register = ""
            maker_color = None
            if "Bluetooth_MAC" in car_data:
                bluetooth_MAC = car_data["Bluetooth_MAC"]
            if "Bluetooth_Name" in car_data:
                bluetooth_name = car_data["Bluetooth_Name"]
            if "Register" in car_data:
                register = car_data["Register"]
            if "Marker_Color" in car_data:
                maker_color = car_data["Marker_Color"]

            Car.update_car(car_data["ID_car"], bluetooth_MAC, bluetooth_name, car_data["Brand"], car_data["Name"],
                           register, maker_color)

            right = StatusReturn(19, "editCar")
            self.response.write(right.print_result())
Exemplo n.º 16
0
    def post(self):
        if User_tool.check_before_start("getAllCars_groupID", self) >= 0:
            data = json.loads(self.request.body)
            try:
                # id_groups = User_tool.return_groups(data["Email"])
                result = []
                # if(id_groups>0):
                # for key in id_groups:
                id_car_by_group = Car_group.getCarFromGroup(data["ID_group"])

                for carTemp in id_car_by_group:
                    result.append((Car.getCarbyID(carTemp.id_car)).to_string_json_car())

                result_json = StatusReturn(2, "getAllCars_groupID", result)
                self.response.write(result_json.print_result())
            except:
                self.error(500)
                error = StatusReturn(6, "getAllCars_groupID")
                self.response.write(error.print_general_error())
Exemplo n.º 17
0
    def post(self):
        if User_tool.check_before_start("createCar", self) >= 0:
            data = json.loads(self.request.body)
            if "Bluetooth_MAC" in data:
                new_car = Car(name=data["Name"], latitude="0", longitude="0", timestamp=str(datetime.datetime.now()),
                              email=data["Email"], bluetooth_MAC=data["Bluetooth_MAC"],
                              bluetooth_name=data["Bluetooth_name"], brand=data["Brand"])
            else:
                new_car = Car(name=data["Name"], latitude="0", longitude="0", timestamp=str(datetime.datetime.now()),
                              email=data["Email"], brand=data["Brand"])

            new_car.put()

            right = StatusReturn(4, "createCar", new_car.key.id())
            self.response.write(right.print_result())
Exemplo n.º 18
0
    def post(self):
        if User_tool.check_before_start("createCar", self) >= 0:
            dati = json.loads(self.request.body)
            car_data = dati["Car"]
            user_data = dati["User"]
            bluetooth_MAC = ""
            bluetooth_name = ""
            register = ""
            uuid = ""
            bmaj = ""
            bmin = ""
            marker_color = None

            if "Bluetooth_MAC" in car_data:
                bluetooth_MAC = car_data["Bluetooth_MAC"]
            if "Bluetooth_Name" in car_data:
                bluetooth_name = car_data["Bluetooth_Name"]
            if "Register" in car_data:
                register = car_data["Register"]
            if "Marker_Color" in car_data:
                marker_color = car_data["Marker_Color"]

            new_car = Car(name=car_data["Name"], latitude="0", longitude="0", timestamp=str(datetime.datetime.now()),
                          email=user_data["Email"], bluetooth_MAC=bluetooth_MAC, bluetooth_name=bluetooth_name,
                          brand=car_data["Brand"], register=register, isParked=False, lastdriver=user_data["Email"],
                          uuid=uuid, marker_color=marker_color)

            new_car = new_car.put()
            list_user = car_data["Users"]
            searchuser = User.static_querySearch_email(user_data["Email"])
            for user in searchuser:

                if static_variable.DEBUG:
                    logging.debug(user.key.id())
                new_contact_car = User_car(id_user=user.key.id(), id_car=(new_car.id()))
                new_contact_car.put()
            for user in list_user:
                userEmail = user["Email"]
                user_key = User.is_user_check(userEmail)
                if user_key == 0:
                    new_user = User(id_android=None, code=0, temp_code=0, email=userEmail, nickname=None, is_user=0)
                    temp_user_key = new_user.put()
                    user_key = temp_user_key.id()
                if User_car.check_user_exist(user_key, new_car.id()) > 0:
                    new_contact_car = User_car(id_user=user_key, id_car=new_car.id())
                    new_contact_car.put()
            right = StatusReturn(4, "createCar", new_car.id())
            self.response.write(right.print_result())
Exemplo n.º 19
0
 def post(self):
     if User_tool.check_before_start("deleteCar", self) >= 0:
         data = json.loads(self.request.body)
         Car.delete_car_ID(data["ID"])
         right = StatusReturn(7, "deleteCar", "Delete " + str(data["ID"]))
         self.response.write(right.print_result())
Exemplo n.º 20
0
    def post(self):
        if User_tool.check_before_start("createCar", self) >= 0:
            dati = json.loads(self.request.body)
            car_data = dati["Car"]
            user_data = dati["User"]
            bluetooth_MAC = ""
            bluetooth_name = ""
            register = ""
            uuid = ""
            bmaj = ""
            bmin = ""
            marker_color = None

            if "Bluetooth_MAC" in car_data:
                bluetooth_MAC = car_data["Bluetooth_MAC"]
            if "Bluetooth_Name" in car_data:
                bluetooth_name = car_data["Bluetooth_Name"]
            if "Register" in car_data:
                register = car_data["Register"]
            if "Marker_Color" in car_data:
                marker_color = car_data["Marker_Color"]

            new_car = Car(name=car_data["Name"],
                          latitude="0",
                          longitude="0",
                          timestamp=str(datetime.datetime.now()),
                          email=user_data["Email"],
                          bluetooth_MAC=bluetooth_MAC,
                          bluetooth_name=bluetooth_name,
                          brand=car_data["Brand"],
                          register=register,
                          isParked=False,
                          lastdriver=user_data["Email"],
                          uuid=uuid,
                          marker_color=marker_color)

            new_car = new_car.put()
            list_user = car_data["Users"]
            searchuser = User.static_querySearch_email(user_data["Email"])
            for user in searchuser:

                if static_variable.DEBUG:
                    logging.debug(user.key.id())
                new_contact_car = User_car(id_user=user.key.id(),
                                           id_car=(new_car.id()))
                new_contact_car.put()
            for user in list_user:
                userEmail = user["Email"]
                user_key = User.is_user_check(userEmail)
                if user_key == 0:
                    new_user = User(id_android=None,
                                    code=0,
                                    temp_code=0,
                                    email=userEmail,
                                    nickname=None,
                                    is_user=0)
                    temp_user_key = new_user.put()
                    user_key = temp_user_key.id()
                if User_car.check_user_exist(user_key, new_car.id()) > 0:
                    new_contact_car = User_car(id_user=user_key,
                                               id_car=new_car.id())
                    new_contact_car.put()
            right = StatusReturn(4, "createCar", new_car.id())
            self.response.write(right.print_result())