def main(): route4me = Route4Me(API_KEY) address_book = route4me.address_book response = address_book.create_contact( first_name="Juan", last_name="Pimentel", address_1="17205 RICHMOND TNPK, MILFORD, VA, 22514", cached_lat=38.024654, cached_lng=-77.338814, ) if isinstance(response, dict) and 'errors' in response.keys(): print('. '.join(response['errors'])) else: print('Address ID: {0}'.format(response['address_id'])) print('First Name: {0}'.format(response['first_name'])) print('Last Name: {0}'.format(response['last_name'])) print('Address: {0}'.format(response['address_1'])) print('Deleting this Contact') address_ids = [ response['address_id'], ] response = address_book.delete_addressbook_contact( address_ids=address_ids) if isinstance(response, dict) and 'errors' in response.keys(): print('. '.join(response['errors'])) else: print('Deleted: {}'.format(response['status']))
def main(): route4me = Route4Me(API_KEY) avoidance_zones = route4me.avoidance_zones print('Creating Circle Shape Zone') territory = { "territory_name": "Circle Territory", "territory_color": "ff0000", "territory": { "type": "circle", "data": [ "37.569752822786455,-77.47833251953125", "5000", ] } } response = avoidance_zones.add_avoidance_zone(**territory) if isinstance(response, dict) and 'errors' in response.keys(): print('. '.join(response['errors'])) else: print('Territory ID: {}'.format(response['territory_id'])) print('\tTerritory Name: {}'.format(response['territory_name'])) print('\tTerritory Color: {}'.format(response['territory_color'])) print('\tMember ID: {}'.format(response['member_id'])) print('\tTerritory Type: {}'.format(response['territory']['type'])) if response['territory']['data']: print('\tData:') for data in response['territory']['data']: print('\t\t{0}'.format(data))
def main(): route4me = Route4Me(KEY) avoidance_zones = route4me.avoidance_zones print('Creating Rectangular Shape Zone') territory = { "territory_name": "Rect Territory", "territory_color": "ff0000", "territory": { "type": "rect", "data": [ "43.51668853502909,-109.3798828125", "46.98025235521883,-101.865234375" ] } } response = avoidance_zones.add_avoidance_zone(**territory) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: print('Territory ID: {}'.format(response.territory_id)) print('\tTerritory Name: {}'.format(response.territory_name)) print('\tTerritory Color: {}'.format(response.territory_color)) print('\tMember ID: {}'.format(response.member_id)) print('\tTerritory Type: {}'.format(response.territory.type)) if response.territory.data: print('\tData:') for data in response.territory.data: print('\t\t{0}'.format(data))
def main(): route4me = Route4Me(KEY) address_book = route4me.address_book response = address_book.create_contact( first_name="Juan", last_name="Pimentel", address_1="17205 RICHMOND TNPK, MILFORD, VA, 22514", cached_lat=38.024654, cached_lng=-77.338814, ) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: print('Address ID: {0}'.format(response.address_id)) print('First Name: {0}'.format(response.first_name)) print('Last Name: {0}'.format(response.last_name)) print('Address: {0}'.format(response.address_1)) print('Deleting this Contact') address_ids = [ response.address_id, ] response = address_book.delete_addressbook_contact( address_ids=address_ids) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: print('Deleted: {}'.format(response.status))
def main(): r4m = Route4Me(API_KEY) route = r4m.route response = route.get_routes(limit=1, offset=0) if isinstance(response, dict) and 'errors' in response.keys(): print('. '.join(response['errors'])) else: route_id = response[0]['route_id'] print('Route ID: {}'.format(route_id)) response = route.get_route(route_id=route_id) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: data = { "route_path_output": 'Points', "route_id": route_id } response = route.get_route_path_points(**data) print('Optimization Problem ID: {}'.format( response['optimization_problem_id'] )) for i, address in enumerate(response['addresses']): print('Address #{}'.format(i + 1)) print('\tAddress: {0}'.format(address['address'])) print('\tRoute Destination ID: {0}'.format( address['route_destination_id'] )) if 'path_to_next' in address.keys(): for i, path in enumerate(address['path_to_next']): print('\t{0} - \tlat: {1} \tlng: {2}'.format(i + 1, path['lat'], path['lng']))
def main(): route4me = Route4Me(API_KEY) order = route4me.order url = "http://www.bk.com/restaurants/ny/new-york/106-fulton-st-17871.html" data = { 'address_1': '106 Fulton St, Farmingdale, NY 11735, USA', 'cached_lat': 40.730730, 'cached_lng': -73.459283, 'address_alias': 'BK Restaurant #: 17871', 'EXT_FIELD_phone': '(212) 566-5132', 'day_scheduled_for_YYMMDD': '2016-07-01', 'EXT_FIELD_custom_data': { 'url': url, } } response = order.create_order(**data) if isinstance(response, dict) and 'errors' in response.keys(): print('. '.join(response['errors'])) else: order_id = response.get('order_id') if order_id: response = order.get_order(order_id=order_id) print('Member ID:\t{0}'.format(response.get('member_id'))) print('Order ID:\t{0}'.format(response.get('order_id'))) print('Order Status ID:\t{0}'.format(response.get('order_status_id'))) print('In Route Count:\t{0}'.format(response.get('in_route_count'))) print('Day Added:\t{0}'.format(response.get('day_added_YYMMDD'))) print('Is Pending:\t{0}'.format(response.get('is_pending'))) print('Is Accepted:\t{0}'.format(response.get('is_accepted'))) print('Is Started:\t{0}'.format(response.get('is_started'))) print('Is Validated:\t{0}'.format(response.get('is_validated'))) print('Is Completed:\t{0}'.format(response.get('is_completed'))) else: print('Error Getting Order')
def main(): route4me = Route4Me(API_KEY) avoidance_zones = route4me.avoidance_zones print('Creating Poly Zone') territory = { "territory_name": "Polygon Territory", "territory_color": "ff0000", "territory": { "type": "poly", "data": [ "56.127184156131065,56.93115234375", "58.41322259056806,59.501953125", "61.53840616716746,59.315185546875", "61.047650586031104,51.998291015625", "59.254649544483726,53.63525390625", "56.47462805805596,54.42626953125" ] } } response = avoidance_zones.add_avoidance_zone(**territory) if isinstance(response, dict) and 'errors' in response.keys(): print('. '.join(response['errors'])) else: territory_id = response['territory_id'] print('Territory ID: {0} -> Created'.format(territory_id)) response = avoidance_zones.delete_avoidance_zone( territory_id=territory_id) if isinstance(response, dict) and 'errors' in response.keys(): print('. '.join(response['errors'])) else: print('Territory ID: {0} -> Deleted: {1}'.format( territory_id, response['status']))
def main(): r4m = Route4Me(KEY) route = r4m.route response = route.get_routes(limit=10, Offset=5) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: response = route.get_route(route_id=response[0].route_id) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: print('Route ID: {}'.format(response.route_id)) route_destination_id = response.addresses[1].route_destination_id print('Route Destination ID: {}'.format(route_destination_id)) data = { "route_destination_id": route_destination_id, "route_id": response.route_id, "custom_fields": { "SDK": "Python" } } response = route.update_route_destination_custom_data(**data) print('Optimization Problem ID: {}'.format( response.optimization_problem_id)) print('Route ID: {}'.format(response.route_id)) print('\tAddress: {0}'.format(response.address)) print('\tRoute Destination ID: {0}'.format( response.route_destination_id)) print('\tCustom Fields: {0}'.format(response.custom_fields))
def main(): route4me = Route4Me(KEY) territories = route4me.territory print('Creating Poly Territory') territory = { "territory_name": "Polygon Territory", "territory_color": "ff0000", "territory": { "type": "poly", "data": [ "56.127184156131065,56.93115234375", "58.41322259056806,59.501953125", "61.53840616716746,59.315185546875", "61.047650586031104,51.998291015625", "59.254649544483726,53.63525390625", "56.47462805805596,54.42626953125" ] } } response = territories.add_territory(**territory) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: territory_id = response.territory_id print('Territory ID: {0} -> Created'.format(territory_id)) response = territories.delete_territory(territory_id=territory_id) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: print('Territory ID: {0} -> Deleted: {1}'.format(territory_id, response.status))
def main(): route4me = Route4Me(KEY) file_uploading = route4me.file_uploading upload_id = 'b2130b5fc36ae1109ef63b6db73781f6' response = file_uploading.get_file_preview(format='json', strUploadID=upload_id) print(response)
def main(): r4m = Route4Me(KEY) route = r4m.route response = route.get_routes(limit=10, Offset=5) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: response = route.get_route(route_id=response[0].route_id) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: print('Route ID: {}'.format(response.route_id)) route_destination_id = response.addresses[1].route_destination_id route_destination_id2 = response.addresses[2].route_destination_id data = { "route_destination_id": route_destination_id, "route_id": response.route_id, "addresses": [{ "route_destination_id": route_destination_id2, "sequence_no": 2, }] } response = route.resequence_route(**data) print('Optimization Problem ID: {}'.format( response.optimization_problem_id)) print('Route ID: {}'.format(response.route_id)) for i, address in enumerate(response.addresses): print('Address #{}'.format(i)) print('\tAddress: {0}'.format(address.address)) print('\tRoute Destination ID: {0}'.format( address.route_destination_id))
def main(): route4me = Route4Me(KEY) route = route4me.route response = route.get_routes(limit=10, Offset=5) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: params = { 'route_id': response[0].route_id, 'directions': 1, 'route_path_output': ROUTE_PATH_OUTPUT.POINTS, 'device_tracking_history': 1, 'limit': 10, 'offset': 5, } response = route.get_route(**params) print("Optimization Problem id: {}".format( response.optimization_problem_id)) print("Trip distance: {}".format(response.trip_distance)) print("Miles per Gallon: {}".format(response.mpg)) for i, direction in enumerate(response.directions): print('Address #{}'.format(i)) print('Start Location: {}'.format( direction.location.start_location)) print('End Location: {}'.format(direction.location.end_location)) print('Distance: {}'.format(direction.location.segment_distance)) print('Time: {}'.format(direction.location.time)) print('===>Steps') for j, step in enumerate(direction.steps): print('\tstep #{}'.format(j)) print('\tDirections: {}'.format(step.directions)) print('\tDuration: {} sec'.format(step.duration_sec)) print('\tCompass Direction: {}'.format(step.compass_direction))
def main(): route4me = Route4Me(API_KEY) route = route4me.route response = route.get_routes(limit=1, offset=0) if isinstance(response, dict) and 'errors' in response.keys(): print('. '.join(response['errors'])) else: route_id = response[0]['route_id'] print('Route ID: {}'.format(route_id)) response = route.get_route(route_id=route_id) if isinstance(response, dict) and 'errors' in response.keys(): print('. '.join(response['errors'])) else: address = response['addresses'][0] route_destination_id = address['route_destination_id'] response = route4me.address.get_address_notes( route_id=route_id, route_destination_id=route_destination_id, ) if isinstance(response, dict) and 'errors' in response.keys(): print('. '.join(response['errors'])) else: print('Address: {}'.format(response['address'])) print('Notes') for i, note in enumerate(response['notes']): print('\t{0} - {1} - {2}'.format(i + 1, note['contents'], note['activity_type']))
def main(): r4m = Route4Me(KEY) route = r4m.route response = route.get_routes(limit=10, Offset=5) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: response = route.get_route(route_id=response[0].route_id) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: print('Route ID: {}'.format(response.route_id)) data = { "route_path_output": 'Points', "route_id": response.route_id } response = route.get_route_path_points(**data) print('Optimization Problem ID: {}'.format( response.optimization_problem_id)) print('Route ID: {}'.format(response.route_id)) for i, address in enumerate(response.addresses): print('Address #{}'.format(i)) print('\tAddress: {0}'.format(address.address)) print('\tRoute Destination ID: {0}'.format( address.route_destination_id)) for i, path in enumerate(address.path_to_next): print('\t{0} - \tlat: {1} \tlng: {2}'.format( i + 1, path.lat, path.lng))
def main(): route4me = Route4Me(KEY) rapid_address = route4me.rapid_address response = rapid_address.get_street_data() for street in response: print('Street Name:\t{0}\t\tZip Code:\t{1}'.format( street.get('street_name'), street.get('zipcode')))
def main(): route4me = Route4Me(KEY) route = route4me.route response = route.get_routes(limit=10, Offset=5) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: response = route.get_route(route_id=response[0].route_id) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: route_id = response.route_id route_destination_id = response.addresses[0].route_destination_id lat = response.addresses[0].lat lng = response.addresses[0].lng note = 'Test Note Contents' response = route4me.address.add_address_notes( note, route_id=route_id, device_type=DEVICE_TYPE.WEB, activity_type='wrongdelivery', dev_lat=lat, dev_lng=lng, address_id=route_destination_id, ) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: print('Note ID: {}'.format(response.note_id)) print('Note contents: {}'.format(response.note.contents)) print('Route ID: {}'.format(response.note.route_id)) print('Route Destination ID: {}'.format( response.note.route_destination_id))
def main(): route4me = Route4Me(KEY) avoidance_zones = route4me.avoidance_zones print('Creating Circle Shape Zone') territory = { "territory_name": "Circle Territory", "territory_color": "ff0000", "territory": { "type": "circle", "data": [ "37.569752822786455,-77.47833251953125", "5000", ] } } response = avoidance_zones.add_avoidance_zone(**territory) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: print('Territory ID: {}'.format(response.territory_id)) print('\tTerritory Name: {}'.format(response.territory_name)) print('\tTerritory Color: {}'.format(response.territory_color)) print('\tMember ID: {}'.format(response.member_id)) print('\tTerritory Type: {}'.format(response.territory.type)) if response.territory.data: print('\tData:') for data in response.territory.data: print('\t\t{0}'.format(data))
def main(): route4me = Route4Me(KEY) avoidance_zones = route4me.avoidance_zones print('Creating Polygon Shape Zone') territory = { "territory_name": "Polygon Territory", "territory_color": "ff0000", "territory": { "type": "poly", "data": [ "56.127184156131065,56.93115234375", "58.41322259056806,59.501953125", "61.53840616716746,59.315185546875", "61.047650586031104,51.998291015625", "59.254649544483726,53.63525390625", "56.47462805805596,54.42626953125" ] } } response = avoidance_zones.add_avoidance_zone(**territory) if hasattr(response, 'errors'): print('. '.join(response.errors)) else: print('Territory ID: {}'.format(response.territory_id)) print('\tTerritory Name: {}'.format(response.territory_name)) print('\tTerritory Color: {}'.format(response.territory_color)) print('\tMember ID: {}'.format(response.member_id)) print('\tTerritory Type: {}'.format(response.territory.type)) if response.territory.data: print('\tData:') for data in response.territory.data: print('\t\t{0}'.format(data))
def main(): route4me = Route4Me(API_KEY) addresses = [ { 'address': '455 S 4th St, Louisville, KY 40202' }, { 'address': '1604 PARKRIDGE PKWY, Louisville, KY, 40214' }, { 'address': '1407 MCCOY, Louisville, KY, 40215' }, { 'address': '4805 BELLEVUE AVE, Louisville, KY, 40215' }, { 'address': '730 CECIL AVENUE, Louisville, KY, 40211' }, ] for address in addresses: print('Original Address: {0}'.format(address)) geocode_error, address = route4me.address.fix_geocode(address) if geocode_error: print('Geocoding Error: {0}'.format(geocode_error)) print('Geocoded Address: {0}'.format(address))
def main(): route4me = Route4Me(API_KEY) rapid_address = route4me.rapid_address response = rapid_address.get_street_data(pk=33) print('Street Name:\t{0}\t\tZip Code:\t{1}'.format( response.get('street_name'), response.get('zipcode')))
def main(): r4m = Route4Me(API_KEY) route = r4m.route response = route.get_routes(limit=1, offset=0) if isinstance(response, dict) and 'errors' in response.keys(): print('. '.join(response['errors'])) else: route_id = response[0]['route_id'] print('Route ID: {}'.format(route_id)) response = route.get_route(route_id=route_id) if isinstance(response, dict) and 'errors' in response.keys(): print('. '.join(response['errors'])) else: route_destination_id = response['addresses'][1][ 'route_destination_id'] print('Route Destination ID: {}'.format(route_destination_id)) data = { "route_destination_id": route_destination_id, "route_id": route_id, "custom_fields": { "SDK": "Python" } } response = route.update_route_destination_custom_data(**data) print('Route ID: {}'.format(route_id)) print('\tAddress: {0}'.format(response['address'])) print('\tRoute Destination ID: {0}'.format( response['route_destination_id'])) print('\tCustom Fields: {0}'.format(response['custom_fields']))
def main(): route4me = Route4Me(API_KEY) avoidance_zones = route4me.avoidance_zones print('Creating Rectangular Shape Zone') territory = { "territory_name": "Rect Territory", "territory_color": "ff0000", "territory": { "type": "rect", "data": [ "43.51668853502909,-109.3798828125", "46.98025235521883,-101.865234375" ] } } response = avoidance_zones.add_avoidance_zone(**territory) if isinstance(response, dict) and 'errors' in response.keys(): print('. '.join(response['errors'])) else: print('Territory ID: {}'.format(response['territory_id'])) print('\tTerritory Name: {}'.format(response['territory_name'])) print('\tTerritory Color: {}'.format(response['territory_color'])) print('\tMember ID: {}'.format(response['member_id'])) print('\tTerritory Type: {}'.format(response['territory']['type'])) if response['territory']['data']: print('\tData:') for data in response['territory']['data']: print('\t\t{0}'.format(data))
def main(): route4me = Route4Me(KEY) file_uploading = route4me.file_uploading filename = '4 addresses linked 2 New Filters.xlsx' upload_file = open(filename, 'rb') files = {'strFilename': upload_file} response = file_uploading.upload_file(files=files, format='json') print(response)
def main(): route4me = Route4Me(API_KEY) address_book = route4me.address_book print('Searching "Juan" in Addressbook') response = address_book.get_addressbook_contacts( limit=10, offset=0, query='juan', fields='first_name,address_email') for row in response.get('results', []): print('First Name: {} - Email: {}'.format(*row))
def main(): route4me = Route4Me(KEY) file_uploading = route4me.file_uploading filename = '10-Stops-MultiDepotSmall.csv' upload_file = open(filename, 'rb') files = {'strFilename': upload_file} response = file_uploading.upload_file(files=files, format='json') print(response)
def main(): route4me = Route4Me(KEY) rapid_address = route4me.rapid_address response = rapid_address.get_street_data_service(housenumber=1800, zipcode=33166) for street in response: print('Street Name:\t{0}\t\tZip Code:\t{1}'.format( street.get('street_name'), street.get('zipcode')))
def main(): route4me = Route4Me(API_KEY) rapid_address = route4me.rapid_address response = rapid_address.get_street_data_zip(zipcode=33166, offset=10, limit=20) for street in response: print('Street Name:\t{0}\t\tZip Code:\t{1}'.format( street.get('street_name'), street.get('zipcode')))
def main(): route4me = Route4Me(KEY) file_uploading = route4me.file_uploading file_path = os.path.dirname(os.path.abspath(__file__)) filename = os.path.join(file_path, '10-Stops-MultiDepotSmall.csv') upload_file = open(filename, 'rb') files = {'strFilename': upload_file} response = file_uploading.upload_file(files=files, format='json') print(response)
def main(): route4me = Route4Me(KEY) file_uploading = route4me.file_uploading file_path = os.path.dirname(os.path.abspath(__file__)) filename = os.path.join(file_path, '4 addresses linked 2 New Filters.xlsx') upload_file = open(filename, 'rb') files = {'strFilename': upload_file} response = file_uploading.upload_file(files=files, format='json') print(response)
def main(): route4me = Route4Me(KEY) activity_feed = route4me.activity_feed response = activity_feed.log_specific_message( activity_message='Hello from Python SDK', route_id='D2F447BCB1F8B8388E88B07188B3A256') if hasattr(response, 'errors'): print('. '.join(response.errors)) else: print('Message Logged: {}'.format(response.status))