Exemplo n.º 1
0
def request_lyft(code, state):
    """Request an Lyft."""

    redirect_url = "http://0.0.0.0:5000/callback_lyft?code=%s&state=%s" % (
        code, state)
    lyft_session = lyft_auth_flow.get_session(redirect_url)
    lyft_ride_client = LyftRidesClient(lyft_session)

    credentials = lyft_session.oauth2credential
    access_tokenn = credentials.access_token

    response = lyft_ride_client.request_ride(
        ride_type=session["lyft_ride_type"],
        start_latitude=session["origin_lat"],
        start_longitude=session["origin_lng"],
        end_latitude=session["dest_lat"],
        end_longitude=session["dest_lng"])

    ride_details = response.json

    time = lyft_client.get_pickup_time_estimates(session["origin_lat"],
                                                 session["origin_lng"],
                                                 session["lyft_ride_type"])

    eta = time.json
    minutes = eta["eta_estimates"][0]["eta_seconds"] / 60

    session["ride_type"] = "Lyft"

    get_time(minutes)
Exemplo n.º 2
0
def order():

    auth_flow = AuthorizationCodeGrant(
        creds.lyft_client_id,
        creds.lyft_client_secret,
        "public",
        )
    auth_url = auth_flow.get_authorization_url()
    my_redirect_url = input(print("Redirected URL: ")).strip()
    session = auth_flow.get_session(my_redirect_url)
    client = LyftRidesClient(session)
    x = len(client.get_pickup_time_estimates(lyft_start_latitude, lyft_start_longitude).json['eta_estimates'])
    y = 0
    lyft_eta_seconds = []
    while y < x:
        lyft_eta_seconds.append(client.get_pickup_time_estimates(lyft_start_latitude, lyft_start_longitude).json['eta_estimates'][y]['eta_seconds'])
        y += 1
    eta_seconds = int(min(lyft_eta_seconds))
    response = client.request_ride(
        ride_type='lyft',
        start_latitude=lyft_start_latitude,
        start_longitude=lyft_start_longitude,
        end_latitude=lyft_end_latitude,
        end_longitude=-lyft_end_longitude,
    )