-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathestimate_ground_transit_time.py
36 lines (29 loc) · 1.18 KB
/
estimate_ground_transit_time.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import logging
import sys
from example_config import CONFIG_OBJ
from fedex.services.availability_commitment_service import FedexAvailabilityCommitmentRequest
from fedex.tools.conversion import sobject_to_dict
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
avc_request = FedexAvailabilityCommitmentRequest(CONFIG_OBJ)
# .StateOrProvinceCode available as well
avc_request.Origin.PostalCode = '60634'
avc_request.Origin.CountryCode = 'US'
avc_request.Destination.PostalCode = '19106'
avc_request.Destination.CountryCode = 'US'
avc_request.Service = 'FEDEX_GROUND'
avc_request.send_request()
response_dict = sobject_to_dict(avc_request.response)
# output display formatting
origin_str = '%s, %s' % (
avc_request.Origin.PostalCode,
avc_request.Origin.CountryCode)
destination_str = '%s, %s' % (
avc_request.Destination.PostalCode,
avc_request.Destination.CountryCode)
logging.info('origin: %s' % origin_str)
logging.info('destination: %s' % destination_str)
for option in response_dict['Options']:
if option['Service'] == 'FEDEX_GROUND':
logging.info('TransitTime: %s' % option['TransitTime'])
else:
logging.warning('No Fedex Ground Service found.')