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 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 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 get_local(): global access vehicle_ids = smartcar.get_vehicle_ids(access['access_token'])['vehicles'] vehicle = smartcar.Vehicle(vehicle_ids[0], access['access_token']) response = vehicle.location() print(response) return ""
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(): # 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 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 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 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 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 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 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 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 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 test_get_vehicle_ids(self): query = { 'limit': 11, 'offset': 1 } access_token = 'access_token' url = smartcar.const.API_URL + '/vehicles?' + urlencode(query) responses.add('GET', url, json=self.expected, match_querystring=True) actual = smartcar.get_vehicle_ids(access_token, limit=query['limit'], offset=query['offset']) self.assertEqual(actual, self.expected) self.assertEqual(request().headers['Authorization'], 'Bearer ' + access_token)
def read_odom(): global access vehicle_ids = smartcar.get_vehicle_ids(access['access_token'])['vehicles'] vehicle = smartcar.Vehicle(vehicle_ids[0], access['access_token']) response = vehicle.odometer() print(response) print(response["data"]["distance"]) return ""
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 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 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 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 smart_unlock(): global access vehicle_ids = smartcar.get_vehicle_ids(access['access_token'])['vehicles'] vehicle = smartcar.Vehicle(vehicle_ids[0], access['access_token']) print(vehicle) vehicle.unlock() global locked locked = 0 return redirect(url_for('confirm'))
def get_vehicle_ids(self): if not self.load_access_token(): return None vehicle_ids = sc.get_vehicle_ids( self.access['access_token'])['vehicles'] print(vehicle_ids) # Error check if vehicles exists / access token expired return vehicle_ids
def exchange(): global access global vehicle_ids code = request.args.get('code') access = client.exchange_code(code) vehicle_ids = smartcar.get_vehicle_ids(access['access_token'])['vehicles'] return redirect("index")
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')
def callback(): code = request.args.get('code') access = client.exchange_code(code) session['access_token'] = access['access_token'] access_token = session['access_token'] response = smartcar.get_vehicle_ids(access_token) print(response['vehicles']) session['vid'] = response['vehicles'][1] session['vin'] = smartcar.Vehicle(session['vid'], access_token).vin() return redirect('/security')
def test_get_vehicle_ids(self): query = {"limit": 11, "offset": 1} access_token = "access_token" url = smartcar.const.API_URL + "/vehicles?" + urlencode(query) responses.add("GET", url, json=self.expected, match_querystring=True) actual = smartcar.get_vehicle_ids(access_token, limit=query["limit"], offset=query["offset"]) self.assertEqual(actual, self.expected) self.assertEqual(request().headers["Authorization"], "Bearer " + access_token)
def get(self): actual_code = self.get_argument('code') #get code codeStr = str(actual_code) global access #change from global in future access = client.exchange_code(actual_code) #get access info access_token = access["access_token"] vehicle_ids_dict = smartcar.get_vehicle_ids(access_token) print(access) vehicles_in_list = vehicle_ids_dict['vehicles'] vehicle_dic = get_cars(vehicles_in_list, access_token) self.render('html/index.html', title="callback", code=codeStr)
def vehicle(): global access vehicle_ids = smartcar.get_vehicle_ids(access['access_token'])['vehicles'] vehicle = smartcar.Vehicle(vehicle_ids[0], access['access_token']) info = vehicle.info() #print(info) response = vehicle.odometer() #print(response) return jsonify(info, response)
def smart_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'] # instantiate the first vehicle in the vehicle id list vehicle = smartcar.Vehicle(vehicle_ids[0], access['access_token']) info = vehicle.info() print(info) return jsonify(info)
def cars(): global access vehicle_ids = smartcar.get_vehicle_ids(access['access_token'])['vehicles'] vehicle = smartcar.Vehicle(vehicle_ids[0], access['access_token']) info = vehicle.info() gps = vehicle.location() odometer = vehicle.odometer() return render_template('results.html', year=info['year'], make=info['make'], model=info['model'], longitude=gps['data']['longitude'], latitude=gps['data']['latitude'], miles=odometer['data']['distance'])