예제 #1
0
def on_button():
    """Run the example.

    Create an UberRidesClient from OAuth 2.0 Credentials, update a sandbox
    product's surge, request and complete a ride.
    """
    credentials = import_oauth2_credentials()
    api_client = create_uber_client(credentials)

    # ride request with upfront pricing flow
    api_client.cancel_current_ride()

    verbose = True

    print("Frage Koordinaten ab...")

    start = get_latlng(START_NAME)
    end = get_latlng(END_NAME)

    # Manually set coordinates
    #UberLocation = namedtuple('UberLocation', 'latitude longitude')
    #start = UberLocation(48, 11)
    #end = UberLocation(48, 10)

    if start is None:
        print("Bitte gültige Startadresse eingeben")
        return
    if end is None:
        print("Bitte gültige Endadresse eingeben")

    print("Start (%s, %s)" % (start.latitude, start.longitude))
    print("Ende (%s, %s)" % (end.latitude, end.longitude))

    #Request a ride with upfront pricing product
    paragraph_print("Anfrage einer Fahrt...\nVon: %s\nNach: %s" % (start, end))
    ride_id, pickup_estimate, fare = request_ufp_ride(api_client,
                                                      start.latitude,
                                                      start.longitude,
                                                      end.latitude,
                                                      end.longitude)

    paragraph_print("Akzeptiere Fahrt...")
    update_ride(api_client, 'accepted', ride_id, verbose=verbose)

    paragraph_print("Warten bis Fahrer da ist...")
    show_ui(pickup_estimate, fare)

    paragraph_print("Einsteigen und losfahren...")
    update_ride(api_client, 'in_progress', ride_id, verbose=verbose)
    time.sleep(5)

    paragraph_print("Am Ziel angekommen...")
    update_ride(api_client, 'completed', ride_id, verbose=verbose)
예제 #2
0
def request_ufp_ride(api_client, start_lat, start_lng, end_lat, end_lng):
    """Use an UberRidesClient to request a ride and print the results.

    Parameters
        api_client (UberRidesClient)
            An authorized UberRidesClient with 'request' scope.

    Returns
        The unique ID of the requested ride.
    """
    try:

        estimate = api_client.estimate_ride(product_id=UFP_PRODUCT_ID,
                                            start_latitude=start_lat,
                                            start_longitude=start_lng,
                                            end_latitude=end_lat,
                                            end_longitude=end_lng,
                                            seat_count=2)
        fare = estimate.json.get('fare')

        request = api_client.request_ride(product_id=UFP_PRODUCT_ID,
                                          start_latitude=start_lat,
                                          start_longitude=start_lng,
                                          end_latitude=end_lat,
                                          end_longitude=end_lng,
                                          seat_count=2,
                                          fare_id=fare['fare_id'])

    except (ClientError, ServerError) as error:
        print(error)
        fail_print(error)
        return

    else:
        #success_print(estimate.json)
        #success_print(request.json)

        fare = estimate.json["fare"]["display"]
        pickup_estimate = estimate.json["pickup_estimate"]
        trip_duration_estimate = estimate.json["trip"]["duration_estimate"] / 60
        paragraph_print(
            "Die Fahrt wird vorraussichtlich %s kosten.\nDer Fahrer kann in %s Minuten da sein.\nDie Fahrdauer bis zum Ziel beträgt %s Minuten"
            % (fare, pickup_estimate, trip_duration_estimate))

        return (request.json.get('request_id'), pickup_estimate, fare)
예제 #3
0
    """
    try:
        ride_details = api_client.get_ride_details(ride_id)

    except (ClientError, ServerError) as error:
        fail_print(error)

    else:
        success_print(ride_details.json)

if __name__ == '__main__':
    
    credentials = import_oauth2_credentials()
    api_client = create_uber_client(credentials)

    paragraph_print("Ride estimates.")
    estimate_ride(api_client)

    paragraph_print("Request a ride.")
    ride_id = request_ride(api_client)

    paragraph_print("Update ride status to accepted.")
    update_ride(api_client, 'accepted', ride_id)

    paragraph_print("Updated ride details.")
    get_ride_details(api_client, ride_id)

    paragraph_print("Update ride status to completed.")
    update_ride(api_client, 'in_progress', ride_id)
    update_ride(api_client, 'completed', ride_id)
예제 #4
0
    else:
        success_print(ride_details.json)


if __name__ == '__main__':
    """Run the example.

    Create an UberRidesClient from OAuth 2.0 Credentials, update a sandbox
    product's surge, request and complete a ride.
    """
    credentials = import_oauth2_credentials()
    api_client = create_uber_client(credentials)

    # ride request with upfront pricing flow

    paragraph_print("Request a ride with upfront pricing product.")
    ride_id = request_ufp_ride(api_client)

    paragraph_print("Update ride status to accepted.")
    update_ride(api_client, 'accepted', ride_id)

    paragraph_print("Updated ride details.")
    get_ride_details(api_client, ride_id)
    update_ride(api_client, 'in_progress', ride_id)

    paragraph_print("Updated ride details.")
    get_ride_details(api_client, ride_id)

    paragraph_print("Update ride status to completed.")
    update_ride(api_client, 'completed', ride_id)
예제 #5
0
    else:
        success_print(ride_details.json)


if __name__ == '__main__':
    """Run the example.

    Create an UberRidesClient from OAuth 2.0 Credentials, update a sandbox
    product's surge, request and complete a ride.
    """
    credentials = import_oauth2_credentials()
    api_client = create_uber_client(credentials)

    # ride request with upfront pricing flow

    paragraph_print("Request a ride with upfront pricing product.")
    ride_id = request_ufp_ride(api_client)

    paragraph_print("Update ride status to accepted.")
    update_ride(api_client, 'accepted', ride_id)

    paragraph_print("Updated ride details.")
    get_ride_details(api_client, ride_id)
    update_ride(api_client, 'in_progress', ride_id)

    paragraph_print("Updated ride details.")
    get_ride_details(api_client, ride_id)

    paragraph_print("Update ride status to completed.")
    update_ride(api_client, 'completed', ride_id)