def incoming_sms(): """Send a dynamic reply to an incoming text message""" # Get the message the user sent our Twilio number body = request.values.get('Body', None) # Start our TwiML response resp = MessagingResponse() # Determine the right reply for this message print(body) if body == 'Hackru2019': global access vehicle_ids = smartcar.get_vehicle_ids( access['access_token'])['vehicles'] # instantiate the first vehicle in the vehicle id list vehicle = smartcar.Vehicle(vehicle_ids[0], access['access_token']) vehicle.unlock() resp.message("Unlocked!") return str(resp) elif body != 'Hackru2019': vehicle_ids = smartcar.get_vehicle_ids( access['access_token'])['vehicles'] # instantiate the first vehicle in the vehicle id list vehicle = smartcar.Vehicle(vehicle_ids[0], access['access_token']) vehicle.lock() resp.message("locked!") return str(resp)
def after_auth(request): if request.method == 'GET': auth_code = request.GET['code'] access = client.exchange_code(auth_code) access_token = access['access_token'] # Saves to sheet smartcar_sheet.update_acell('A2', access_token) response = smartcar.get_vehicle_ids(access_token) vid = response['vehicles'][0] vehicle = smartcar.Vehicle(vid, access_token) location = vehicle.location() latitude = location['data']['latitude'] longitude = location['data']['longitude'] mymap = gmplot.GoogleMapPlotter(latitude, longitude, 10) return render(request, 'carpal/after_auth.html', { 'code': auth_code, 'lat': latitude, 'lon': longitude, 'mymap': mymap })
def location(): #1d3bb4b5-ddeb-492e-974b-43e5dfa68fdd global access_token global refresh_token get_token() print(access_token) vehicle_ids = smartcar.get_vehicle_ids(access_token)['vehicles'] print("The cars") print(vehicle_ids) #instantiate the first vehicle in the vehicle id list #vehicle = smartcar.Vehicle(vehicle_ids[0], access_token) data = [] for element in vehicle_ids: vehicle = smartcar.Vehicle(element, access_token) data.append([element, vehicle.location()]) # TODO: Request Step 4: Make a request to Smartcar API # location = vehicle.location() # print(location) print(data) ''' { "id": "36ab27d0-fd9d-4455-823a-ce30af709ffc", "make": "TESLA", "model": "Model S", "year": 2014 } ''' print() return jsonify(data)
def vehicle(): # access our global variable to retrieve our access tokens global access # the list of vehicle ids vehicle_ids = smartcar.get_vehicle_ids( access['access_token'])['vehicles'] vehicle_summary = strings.header for vid in vehicle_ids: # instantiate the first vehicle in the vehicle id list vehicle = smartcar.Vehicle(vid, access['access_token']) info = '' odometer = '' try: info = vehicle.info() odometer = vehicle.odometer() except TypeError: print("Failed to get info from vehicle %s" % vid) continue compound_name = info['make'] + info['model'] + str(info['year']) vehicle_summary += strings.card % ( info['make'], info['model'], info['make'], info['model'], info['year'], math.floor(odometer['data']['distance'] * 0.000621371), 63, 1284, 918, '#' + compound_name) vehicle_summary += strings.details_modal % (compound_name) vehicle_summary += strings.footer return vehicle_summary
def vehicle(): # TODO: Request Step 2: Get vehicle ids #data = json.loads(json_data) # TODO: Request Step 3: Create a vehicle # TODO: Request Step 4: Make a request to Smartcar API global access # the list of vehicle ids vehicle_ids = smartcar.get_vehicle_ids(access['access_token'])['vehicles'] vehicle = smartcar.Vehicle(vehicle_ids[0], access['access_token']) info = vehicle.info() #lock = vehicle.unlock() print(info) ''' { "id": "36ab27d0-fd9d-4455-823a-ce30af709ffc", "make": "TESLA", "model": "Model S", "year": 2014 } ''' return jsonify(info)
def define_vehicles(): """ Verify and instantiate the variables so we can store car info data @Returns: list of dictionaries containing car details """ global access if access == None: error = 520 errorstr = "Cannot access vehicle data: Not logged in" return jsonify({'error_code':error, 'errorstr':errorstr}) vehicle_ids = smartcar.get_vehicle_ids( access['access_token'])['vehicles'] print(vehicle_ids, flush=True) vehicle = list() for i, v_id in enumerate(vehicle_ids): vehicle.append(smartcar.Vehicle(v_id, access['access_token'])) if _debugflag: print(vehicle[i]) # vehicle = smartcar.Vehicle(vehicle_ids[0], access['access_token']) # TODO: Request Step 4: Make a request to Smartcar API info = list() for i, _ in enumerate(vehicle): info.append(vehicle[i].info()) for i, v in enumerate(vehicle): reading = get_odometer(v) if reading[0] > 0: info[i]['odometer'] = reading coordinates = get_location(v) if coordinates[0] <= 180 and coordinates[1] <= 180: info[i]['location'] = coordinates if _debugflag: print(info, flush=True) return vehicle, info
def all(): # if 'access' not in session: # return redirect('/') access = access_token vehicle_ids = smartcar.get_vehicle_ids(access['access_token'])['vehicles'] newVehicles = [] newVehicles.append({ 'id': 0, 'make': 'Buick', 'model': 'Cascada', 'year': 2018 }) newVehicles.append({ 'id': 1, 'make': 'Chevrolet', 'model': 'Bolt', 'year': 2019 }) newVehicles.append({ 'id': 2, 'make': 'Audi', 'model': 'A4 Sedan', 'year': 2018 }) allVehicles = list( map(lambda v: smartcar.Vehicle(v, access['access_token']).info(), vehicle_ids)) + newVehicles return jsonify(allVehicles), 200
def vehicle(): # TODO: Request Step 2: Get vehicle ids global access # TODO: Request Step 3: Create a vehicle vehicle_ids = smartcar.get_vehicle_ids(access['access_token'])['vehicles'] # TODO: Request Step 4: Make a request to Smartcar API vehicle = smartcar.Vehicle(vehicle_ids[0], access['access_token']) info = vehicle.info() print(info) #response = vehicle.permissions() #print(response) response3 = vehicle.location() print(response3) vehicle.unlock() odometer2 = vehicle.odometer() print(odometer2) return jsonify(info) time_start = time.time() seconds = 0 minutes = 0
def callback(): code = request.args.get('code') id = request.args.get('state') access = client.exchange_code(code) print(access) response = smartcar.get_vehicle_ids(access['access_token']) vehicle_id = response['vehicles'][0] global vehicle vehicle = smartcar.Vehicle(vehicle_id, access['access_token']) # return jsonify(access) response = { "text": "You have successfully signed in! What would you like to do?", "quick_replies":[{ "content_type":"text", "title":"Lock", "payload":"Lock", }, { "content_type":"text", "title":"Unlock", "payload":"Unlock", }, { "content_type":"text", "title":"Find", "payload":"Find", } ] } callSendAPI(id, response) return 'Please close this popup window'
def vehicle(): global access_token global refresh_token get_token() print(access_token) vehicle_ids = smartcar.get_vehicle_ids(access_token)['vehicles'] #instantiate the first vehicle in the vehicle id list data = [] for element in vehicle_ids: vehicle = smartcar.Vehicle(element, access_token) info = vehicle.info() data.append([element, info]) # TODO: Request Step 4: Make a request to Smartcar API info = vehicle.info() print(data) ''' { "id": "36ab27d0-fd9d-4455-823a-ce30af709ffc", "make": "TESLA", "model": "Model S", "year": 2014 } ''' query = info["make"].lower() + info["model"] print("QUERY:", query) pic_url = get_pic(query) d = { "data": data, "picture": pic_url } return jsonify(d)
def vehicle(): # TODO: Request Step 2: Get vehicle ids global access vehicle_ids = smartcar.get_vehicle_ids(access['access_token'])['vehicles'] # TODO: Request Step 3: Create a vehicle vehicle = smartcar.Vehicle(vehicle_ids[0], access['access_token']) # TODO: Request Step 4: Make a request to Smartcar API info = vehicle.info() print(info) ''' { "id": "36ab27d0-fd9d-4455-823a-ce30af709ffc", "make": "TESLA", "model": "Model S", "year": 2014 } ''' location = vehicle.location() print(location) odometer = vehicle.odometer() print(odometer) permissions = vehicle.permissions() print(permissions) return jsonify("Vehicle info: ", info, "\\n Vehicle location: ", location, "\\n Vehicle Odometer: ", odometer, "\\n Permissions: ", permissions) pass
def __init__(self, vehicle_id, access_token): self.vehicle_id = vehicle_id self.access_token = access_token self.vehicle = sc.Vehicle( vehicle_id, access_token )
def emergency_protocol(problem): # Fetch the set of vehicles associated with this access response = smartcar.get_vehicle_ids("2252fdd5-cb00-4e0c-8a3c-57ddb5b80d46") print(response) # Use the first vehicle vehicle = smartcar.Vehicle(response['vehicles'][0], "2252fdd5-cb00-4e0c-8a3c-57ddb5b80d46") # Fetch the vehicle's location location = vehicle.location() print(location) #lock the vehicle vehicle.lock() #texting functionality account_sid = 'AC48e29bfc8e2d0e9e7db0ed92cd8333ee' auth_token = '063956022336f601b581f2ab668bc9e6' client = Client(account_sid, auth_token) message = client.messages.create( body= "Hello, you are receiving a crime tip from WatchDog.io. We are reporting a suspicious incident at Longitude: " + str(location['data']['longitude']) + ", \n Latitude: " + str(location['data']['latitude']) + " at " + str(location['age']), from_='+14159645713', media_url='https://media.wnyc.org/i/800/0/c/85/1/AP_880772131965.jpg', to='+15106314908') print(message.sid)
def unlock(): if request.method == 'POST': data = request.form email = data['email'].replace('.', '__dot__') vehicle_id = data['vehicle_id'] cars_rented = db.child('User').child(email).child('cars_rented').child( 'ids').get().val() if vehicle_id in cars_rented and cars_rented[vehicle_id]: vehicle_access = db.child('Car').child(vehicle_id).child( 'access').get().val()['refresh_token'] new_access = client.exchange_refresh_token(vehicle_access) new_access['expiration'] = str(new_access['expiration']) new_access['refresh_expiration'] = str( new_access['refresh_expiration']) db.child('Car').child(vehicle_id).child('access').set(new_access) vehicle = smartcar.Vehicle(vehicle_id, new_access['access_token']) response = vehicle.api.action('security', 'UNLOCK') print(response.text) return jsonify({'status': 'Success'}) else: return jsonify( {'status': 'You do not have access to this vehicle.'})
def vehicles(): user_id = requests.args.get('user_id') user = db.collection(u'users').document(user_id).get().to_dict() if user['access_token_expire_utc'] - time.time() < 60 * 5: True #Refresh token here access_token = user['access_token'] vehicle_ids = smartcar.get_vehicle_ids(access_token)['vehicles'] response = [] for i in range(len(vehicle_ids)): vehicle = smartcar.Vehicle(vehicle_ids[i], access['access_token']) info = vehicle.info() print(info) vin = vehicle.vin() print(vin) odometer = vehicle.odometer() print(odometer) location = vehicle.location() print(location) data = { "info": info, "vin": vin, "odometer": odometer, "location": location } response.append(data) return jsonify(response)
def get(self): lst = smartcar.get_vehicle_ids(self.ass['access_token']) car = smartcar.Vehicle(lst['vehicles'][0], self.ass['access_token']) res = car.location()['data'] res.update(car.battery()['data']) return res
def location(): global access vehicleId = request.args.get('vehicleId') vehicle = smartcar.Vehicle(vehicleId, access['access_token']) location = vehicle.location() return jsonify(location)
def location(): global access vehicle_ids = smartcar.get_vehicle_ids(access['access_token'])['vehicles'] vehicle = smartcar.Vehicle(vehicle_ids[0], access['access_token']) location = vehicle.location() print(location) return jsonify(location) pass
def setUpClass(cls): super(TestVehicleE2E, cls).setUpClass() access_object = cls.client.exchange_code(cls.code) access_token = access_object['access_token'] vehicle_ids = smartcar.get_vehicle_ids(access_token) cls.vehicle = smartcar.Vehicle(vehicle_ids['vehicles'][0], access_token)
def odometer(): # access our global variable to retrieve our access tokens global access vehicleId = request.args.get('vehicleId') vehicle = smartcar.Vehicle(vehicleId, access['access_token']) odometer = vehicle.odometer() return jsonify(odometer)
def get_location(): # Pulls from sheet access_token = smartcar_sheet.acell('A2').value response = smartcar.get_vehicle_ids(access_token) vid = response['vehicles'][0] vehicle = smartcar.Vehicle(vid, access_token) location = vehicle.location() pos = [location['data']['latitude'], location['data']['longitude']] return pos
def getVehicleFromId(access, id): vehicle_ids = getAllVehicles(access) if id in vehicle_ids: vehicle = [ smartcar.Vehicle(v, access['access_token']) for v in vehicle_ids if v == id ][0] return vehicle return None
def timer_end(): time2['timer_end'] = time.time() vehicle_ids = smartcar.get_vehicle_ids(access['access_token'])['vehicles'] vehicle = smartcar.Vehicle(vehicle_ids[0], access['access_token']) location2['end_location'] = vehicle.location() odometer2['end_odometer'] = vehicle.odometer() print(time2) print(odometer2) print(location2) return redirect('/timer')