def request_surge_ride(api_client, surge_confirmation_id=None): try: request = api_client.request_ride( product_id=SURGE_PRODUCT_ID, start_latitude=START_LAT, start_longitude=START_LNG, end_latitude=END_LAT, end_longitude=END_LNG, surge_confirmation_id=surge_confirmation_id, seat_count=2) except SurgeError as e: surge_message = 'Confirm surge by visiting: \n{}\n' surge_message = surge_message.format(e.surge_confirmation_href) response_print(surge_message) confirm_url = 'Copy the URL you are redirected to and paste here: \n' result = input(confirm_url).strip() querystring = urlparse(result).query query_params = parse_qs(querystring) surge_id = query_params.get('surge_confirmation_id')[0] # automatically try request again return request_surge_ride(api_client, surge_id) except (ClientError, ServerError) as error: fail_print(error) return else: success_print(request.json) return request.json.get('request_id')
def request_ufp_ride(api_client): 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: fail_print(error) return else: success_print(estimate.json) success_print(request.json) return request.json.get('request_id')
def main() -> None: load_dotenv() token = os.getenv('TOKEN') raw_link = get_args().url if not raw_link: error_print('Your link is empty. Try again.') exit() try: protocol, link = raw_link.split('://') \ if 'http' in raw_link else ('http', raw_link) except ValueError: error_print('Wrong url format. Try again.') exit() try: if is_bitlink(link, token): success_print('This link has been clicked {} times.'.format( get_click_count(link, token))) else: success_print('This is your very short link: {}'.format( get_bitlink(f'{protocol}://{link}', token))) except requests.exceptions.HTTPError as e: if e.response.status_code == 400: error_print(e.response.json()['description']) else: error_print(str(e))
def get_ride_details(api_client, ride_id): try: ride_details = api_client.get_ride_details(ride_id) except (ClientError, ServerError) as error: fail_print(error) else: success_print(ride_details.json)
def update_ride(api_client, ride_status, ride_id): try: update_product = api_client.update_sandbox_ride(ride_id, ride_status) except (ClientError, ServerError) as error: fail_print(error) else: message = '{} New status: {}' message = message.format(update_product.status_code, ride_status) success_print(message)
def update_surge(api_client, surge_multiplier): try: update_surge = api_client.update_sandbox_product( SURGE_PRODUCT_ID, surge_multiplier=surge_multiplier, ) except (ClientError, ServerError) as error: fail_print(error) else: success_print(update_surge.status_code)
def estimate_ride(api_client): try: estimate = api_client.estimate_ride( product_id=SURGE_PRODUCT_ID, start_latitude=START_LAT, start_longitude=START_LNG, end_latitude=END_LAT, end_longitude=END_LNG, seat_count=2) except (ClientError, ServerError) as error: fail_print(error) else: success_print(estimate.json)
def hello_user(api_client): """Use an authorized client to fetch and print profile information. Parameters api_client (UberRidesClient) An UberRidesClient with OAuth 2.0 credentials. """ try: response = api_client.get_user_profile() except (ClientError, ServerError) as error: fail_print(error) return else: profile = response.json first_name = profile.get('first_name') last_name = profile.get('last_name') email = profile.get('email') message = 'Hello, {} {}. Successfully granted access token to {}.' message = message.format(first_name, last_name, email) success_print(message) success_print(profile) success_print('---') response = api_client.get_home_address() address = response.json success_print(address) success_print('---') response = api_client.get_user_activity() history = response.json success_print(history)