Exemplo n.º 1
0
    def post(self, id):
        parser = reqparse.RequestParser()
        parser.add_argument("action")
        args = parser.parse_args()
        cmd = ""

        if args["action"] == "START":
            cmd = "START_VEHICLE"

        if args["action"] == "STOP":
            cmd = "STOP_VEHICLE"

        vehicle = gm_start_stop_engine(id, cmd)
        jsonified = json.loads(vehicle)

        if jsonified["status"] == "200":
            logger.info(f"Request with id: {id}: \n{jsonified}")
            status = ""

            if jsonified["actionResult"]["status"] == "EXECUTED":
                status = "success"

            if jsonified["actionResult"]["status"] == "FAILED":
                status = "error"
            return {"status": status}, 200
        if jsonified["status"] == "404":
            logger.error(f"Request with id: {id}: \n{jsonified}")
            return jsonified, 404
        else:
            # Catch all case
            logger.critical(f"Unexpected response from GM API")
            return "Critical Error: Unexpected response from GM API", 404
Exemplo n.º 2
0
    def get(self, id):
        vehicle = gm_get_security_info(id)
        jsonified = json.loads(vehicle)

        if jsonified["status"] == "200":
            if len(jsonified["data"]["doors"]["values"]) == 2:
                logger.info(f"id: {id}: \nChecking if 2 door...")
                smartcar_response = [{
                    "location": (jsonified["data"]["doors"]["values"][1]
                                 ["location"]["value"]),
                    "locked":
                    (True if (jsonified["data"]["doors"]["values"][1]["locked"]
                              ["value"] == 'True') else False)
                }, {
                    "location": (jsonified["data"]["doors"]["values"][0]
                                 ["location"]["value"]),
                    "locked":
                    (True if (jsonified["data"]["doors"]["values"][0]["locked"]
                              ["value"] == 'True') else False)
                }]
                logger.info(f"Request with id: {id}: \n{smartcar_response}")
                return smartcar_response, 200
            if len(jsonified["data"]["doors"]["values"]) == 4:
                logger.info(f"id: {id}: \nChecking if 4 door...")
                smartcar_response = [{
                    "location": (jsonified["data"]["doors"]["values"][1]
                                 ["location"]["value"]),
                    "locked":
                    (True if (jsonified["data"]["doors"]["values"][1]["locked"]
                              ["value"] == 'True') else False)
                }, {
                    "location": (jsonified["data"]["doors"]["values"][0]
                                 ["location"]["value"]),
                    "locked":
                    (True if (jsonified["data"]["doors"]["values"][0]["locked"]
                              ["value"] == 'True') else False)
                }, {
                    "location": (jsonified["data"]["doors"]["values"][2]
                                 ["location"]["value"]),
                    "locked":
                    (True if (jsonified["data"]["doors"]["values"][2]["locked"]
                              ["value"] == 'True') else False)
                }, {
                    "location": (jsonified["data"]["doors"]["values"][3]
                                 ["location"]["value"]),
                    "locked":
                    (True if (jsonified["data"]["doors"]["values"][3]["locked"]
                              ["value"] == 'True') else False)
                }]
                logger.info(f"Request with id: {id}: \n{smartcar_response}")
                return smartcar_response, 200
        if jsonified["status"] == "404":
            logger.error(f"Request with id: {id}: \n{jsonified}")
            return jsonified, 404
        else:
            # Catch all case
            logger.critical(f"Unexpected response from GM API")
            return "Critical Error: Unexpected response from GM API", 404
Exemplo n.º 3
0
    def get(self, id):
        vehicle = gm_get_fuel_battery_level(id)
        jsonified = json.loads(vehicle)

        if jsonified["status"] == "200":
            smartcar_response = {
                "percent": (float(jsonified["data"]["tankLevel"]["value"]) if
                            (jsonified["data"]["tankLevel"]["value"] != "null")
                            else "null")
            }
            logger.info(f"Request with id: {id}: \n{smartcar_response}")
            return smartcar_response, 200

        if jsonified["status"] == "404":
            logger.error(f"Request with id: {id}: \n{jsonified}")
            return jsonified, 404
        else:
            # Catch all case
            logger.critical(f"Unexpected response from GM API")
            return "Critical Error: Unexpected response from GM API", 404
Exemplo n.º 4
0
def send_mail(server, db_file, reciver_list, subject, body=None):
    pythoncom.CoInitialize()
    makepy.GenerateFromTypeLibSpec('Lotus Domino Objects')
    logger.info('init mail client')
    session = DispatchEx('Notes.NotesSession')
    db = session.GetDatabase(server, db_file)
    if not db.IsOpen:
        logger.info('open mail db')
        try:
            db.OPENMAIL
        except Exception as e:
            logger.info('could not open database')

    logger.info("Send email ing")
    doc = db.CREATEDOCUMENT
    doc.sendto = reciver_list
    doc.Subject = subject
    if body:
        doc.Body = body
    doc.SEND(0, reciver_list)
    logger.info('send success')
Exemplo n.º 5
0
    def get(self, id):
        vehicle = gm_get_vehicle_info(id)
        jsonified = json.loads(vehicle)

        if jsonified["status"] == "200":
            smartcar_response = {
                "vin": (jsonified["data"]["vin"]["value"]),
                "color": (jsonified["data"]["color"]["value"]),
                "doorCount": (4 if (jsonified["data"]["fourDoorSedan"]["value"]
                                    == 'True') else 2),
                "driveTrain": (jsonified["data"]["driveTrain"]["value"])
            }
            logger.info(f"Request with id: {id}: \n{smartcar_response}")
            return smartcar_response, 200

        if jsonified["status"] == "404":
            logger.error(f"Request with id: {id}: \n{jsonified}")
            return jsonified, 404
        else:
            # Catch all case
            logger.critical(f"Unexpected response from GM API")
            return "Critical Error: Unexpected response from GM API", 404