| 
11 | 11 | 
 
  | 
12 | 12 | from example_config import CONFIG_OBJ  | 
13 | 13 | from fedex.services.location_service import FedexSearchLocationRequest  | 
 | 14 | +from fedex.tools.response_tools import sobject_to_dict  | 
14 | 15 | 
 
  | 
15 | 16 | # Set this to the INFO level to see the response from Fedex printed in stdout.  | 
16 | 17 | logging.basicConfig(stream=sys.stdout, level=logging.INFO)  | 
 | 
26 | 27 | location_request.MultipleMatchesAction = 'RETURN_ALL'  | 
27 | 28 | 
 
  | 
28 | 29 | # Set constraints, see SearchLocationConstraints definition.  | 
 | 30 | +# For LocationTypesToInclude, see FedExLocationType definition.  | 
29 | 31 | location_request.Constraints.LocationTypesToInclude = ['FEDEX_SELF_SERVICE_LOCATION',  | 
30 | 32 |                                                        'FEDEX_AUTHORIZED_SHIP_CENTER']  | 
31 | 33 | 
 
  | 
 | 
49 | 51 | # good to un-comment to see the variables returned by the FedEx reply.  | 
50 | 52 | # print(location_request.response)  | 
51 | 53 | 
 
  | 
 | 54 | +# This will convert the response to a python dict object. To  | 
 | 55 | +# make it easier to work with.  | 
 | 56 | +print(sobject_to_dict(location_request.response))  | 
 | 57 | + | 
52 | 58 | # Here is the overall end result of the query.  | 
53 |  | -print("HighestSeverity:", location_request.response.HighestSeverity)  | 
 | 59 | +print("HighestSeverity: {}".format(location_request.response.HighestSeverity))  | 
 | 60 | +print("TotalResultsAvailable: {}".format(location_request.response.TotalResultsAvailable))  | 
 | 61 | +print("ResultsReturned: {}".format(location_request.response.ResultsReturned))  | 
 | 62 | + | 
 | 63 | +result = location_request.response.AddressToLocationRelationships[0]  | 
 | 64 | +print("MatchedAddress: {}, {} Residential: {}".format(result.MatchedAddress.PostalCode,  | 
 | 65 | +                                                      result.MatchedAddress.CountryCode,  | 
 | 66 | +                                                      result.MatchedAddress.Residential))  | 
 | 67 | +print("MatchedAddressGeographicCoordinates: {}".format(result.MatchedAddressGeographicCoordinates.strip("/")))  | 
 | 68 | + | 
 | 69 | +# Locations sorted by closest found to furthest.  | 
 | 70 | +locations = result.DistanceAndLocationDetails  | 
 | 71 | +for location in locations:  | 
 | 72 | +    print("Distance: {}{}".format(location.Distance.Value, location.Distance.Units))  | 
 | 73 | + | 
 | 74 | +    location_detail = location.LocationDetail  | 
 | 75 | +    print("LocationID: {}".format(location_detail.LocationId))  | 
 | 76 | +    print("StoreNumber: {}".format(location_detail.StoreNumber))  | 
 | 77 | + | 
 | 78 | +    if hasattr(location_detail, 'LocationContactAndAddress'):  | 
 | 79 | +        contact_and_address = location_detail.LocationContactAndAddress  | 
 | 80 | +        contact_and_address = sobject_to_dict(contact_and_address)  | 
 | 81 | +        print("LocationContactAndAddress Dict: {}".format(contact_and_address))  | 
 | 82 | + | 
 | 83 | +    print("GeographicCoordinates {}".format(getattr(location_detail, 'GeographicCoordinates')))  | 
 | 84 | +    print("LocationType {}".format(getattr(location_detail, 'LocationType')))  | 
 | 85 | + | 
 | 86 | +    if hasattr(location_detail, 'Attributes'):  | 
 | 87 | +        for attribute in location_detail.Attributes:  | 
 | 88 | +            print "Attribute: {}".format(attribute)  | 
 | 89 | + | 
 | 90 | +    print("MapUrl {}".format(getattr(location_detail, 'MapUrl')))  | 
 | 91 | + | 
 | 92 | +    if hasattr(location_detail, 'NormalHours'):  | 
 | 93 | +        for open_time in location_detail.NormalHours:  | 
 | 94 | +            print("NormalHours Dict: {}".format(sobject_to_dict(open_time)))  | 
 | 95 | + | 
 | 96 | +    if hasattr(location_detail, 'HoursForEffectiveDate'):  | 
 | 97 | +        for effective_open_time in location_detail.HoursForEffectiveDate:  | 
 | 98 | +            print("HoursForEffectiveDate Dict: {}".format(sobject_to_dict(effective_open_time)))  | 
 | 99 | + | 
 | 100 | +    if hasattr(location_detail, 'CarrierDetails'):  | 
 | 101 | +        for carrier_detail in location_detail.CarrierDetails:  | 
 | 102 | +            print("CarrierDetails Dict: {}".format(sobject_to_dict(carrier_detail)))  | 
 | 103 | + | 
 | 104 | +    print("")  | 
0 commit comments