cc-py-commons 0.5.13__tar.gz → 0.5.15__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/PKG-INFO +1 -1
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/geolocate.py +156 -132
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons.egg-info/PKG-INFO +1 -1
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/setup.py +1 -1
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/README.md +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/bids/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/bids/bid.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/bids/bid_history.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/bids/bid_history_schema.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/bids/bid_schema.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/carriers/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/carriers/account_carrier_map.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/carriers/account_carrier_map_schema.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/carriers/carrier.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/carriers/carrier_schema.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/carriers/contact.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/carriers/contact_schema.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/config/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/config/c4_account_settings.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/config/env.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/config/mcleod_load_fields.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/config/pc_miler_config.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/db/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/db/connection.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/lanes/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/lanes/carrier_lane.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/lanes/carrier_lane_schema.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/lanes/lane.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/lanes/lane_schema.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/loads/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/loads/equipment.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/loads/equipment_schema.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/loads/equipment_types.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/loads/freighthub_contact.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/loads/freighthub_contact_schema.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/loads/load.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/loads/load_schema.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/loads/load_status.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/loads/location.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/loads/location_schema.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/loads/map_load_response.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/quotes/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/quotes/quote.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/quotes/quote_schema.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/quotes/quote_status.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/rfp/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/rfp/create_table.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/rfp/rfp_status.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/rfp/truck_lane_search_mapper.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/schemas/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/schemas/camel_case_schema.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/analytics/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/analytics/analytics_event.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/booking_agent/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/booking_agent/accept_bid.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/booking_agent/cancel_bid.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/booking_agent/constants.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/booking_agent/counter_bid.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/booking_agent/decline_bid.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/booking_agent/get_bid_by_amazon_order_id.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/booking_agent/get_quote.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/booking_agent/update_bid.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/c4/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/c4/amazon_session_token.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/c4/constants.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/c4/get_account.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/c4/get_account_settings.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/c4/get_integration.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/c4/get_users_for_account.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/c4/refresh_amazon_token.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/carrier_hub/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/carrier_hub/get_carrier.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/carrier_hub/list_carriers.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/carrier_hub/list_contacts.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/carrier_hub/update_contact.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/freight_hub/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/freight_hub/post_freight_hub_load.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/create_account_folder.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/db/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/db/delete_table.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/get_client.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/get_green_screens_lane_price.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/get_import_stat.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/get_lane_price.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/get_lane_price_for_bulk.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/list_clients.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/post_import_stat.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/update_import_stat.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/slack/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/slack/send_slack_message.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/sns/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/sns/book_load_notification.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/sns/booking_agent/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/sns/booking_agent/bid_counter_failure_notification.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/sns/booking_agent/constants.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/sns/booking_agent/send_sns_notification.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/sns/booking_assistant_flow_notification.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/sns/import_movements_notification.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/sns/parsed_carrier_notification.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/sns/sns_service.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/sqs/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/sqs/booking_assistant_flow_event.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/sqs/sqs_service.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/tests/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/tests/test_case_conversion.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/tests/test_lambda_utils.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/tests/test_map_transaction.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/tests/test_temperature_utils.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/transactions/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/transactions/equipment_clas_schema.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/transactions/equipment_class.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/transactions/equipment_mapping.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/transactions/equipment_mapping_schema.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/transactions/map_transaction.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/transactions/transaction.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/transactions/transaction_schema.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/__init__.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/bulk_lane_price_result_utils.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/case_conversion.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/datadog_logger.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/datetimes.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/dimension_utils.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/geocode_location.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/get_delivery_date.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/json_logger.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/lambda_utils.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/local_file.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/logger.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/logger_v2.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/pc_miler_utils.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/price_utils.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/redis.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/s3_file.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/temperature_utils.py +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons.egg-info/SOURCES.txt +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons.egg-info/dependency_links.txt +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons.egg-info/requires.txt +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons.egg-info/top_level.txt +0 -0
- {cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/setup.cfg +0 -0
@@ -25,7 +25,7 @@ def get_location_with_country(city, state, zipcode, country, logger, reset_cache
|
|
25
25
|
from_cache = True
|
26
26
|
else:
|
27
27
|
logger.debug(json.dumps({
|
28
|
-
'message': 'Found
|
28
|
+
'message': 'Found location in cache that was not a match',
|
29
29
|
'city': city,
|
30
30
|
'state': state,
|
31
31
|
'zipcode': zipcode,
|
@@ -50,6 +50,23 @@ def get_location_with_country(city, state, zipcode, country, logger, reset_cache
|
|
50
50
|
from_cache = False
|
51
51
|
data = __get_google_location(city=None, state=None, zipcode=postcode, country=None, logger=logger)
|
52
52
|
|
53
|
+
if data and not data.get('postcode'):
|
54
|
+
matching_location = __get_matching_location_from_cache(city, state, data.get('lat'), data.get('lng'), logger)
|
55
|
+
if matching_location:
|
56
|
+
data['postcode'] = matching_location.get('postcode')
|
57
|
+
else:
|
58
|
+
gmaps = googlemaps.Client(key=app_config.GOOGLE_API_KEY)
|
59
|
+
response = None
|
60
|
+
if zipcode:
|
61
|
+
response = gmaps.geocode(zipcode)
|
62
|
+
elif data.get('lat') and data.get('lng'):
|
63
|
+
response = gmaps.reverse_geocode((data.get('lat'), data.get('lng')))
|
64
|
+
post_code_data = __parse_response(response, city)
|
65
|
+
data['postcode'] = post_code_data['postcode'] if post_code_data else None
|
66
|
+
|
67
|
+
if data.get('postcode'):
|
68
|
+
__cache_location(city, state, zipcode, data, logger)
|
69
|
+
|
53
70
|
if data:
|
54
71
|
if not from_cache:
|
55
72
|
__cache_location(city, state, zipcode, data, logger)
|
@@ -127,7 +144,10 @@ def __get_google_distance(origin_latitude, origin_longitude, destination_latitud
|
|
127
144
|
|
128
145
|
def __get_google_location(city, state, zipcode, country, logger):
|
129
146
|
try:
|
147
|
+
if (not city or not state) and not zipcode:
|
148
|
+
return None
|
130
149
|
loc_str = ''
|
150
|
+
data = None
|
131
151
|
|
132
152
|
if city:
|
133
153
|
loc_str = city
|
@@ -150,123 +170,6 @@ def __get_google_location(city, state, zipcode, country, logger):
|
|
150
170
|
|
151
171
|
loc_str = loc_str + country
|
152
172
|
|
153
|
-
def __parse_response(response):
|
154
|
-
if not response or len(response) == 0:
|
155
|
-
return None
|
156
|
-
'''
|
157
|
-
Sample response of Google Maps API for address: Cincinati, OH, 45204
|
158
|
-
{
|
159
|
-
"address_components": [
|
160
|
-
{
|
161
|
-
"long_name": "45204",
|
162
|
-
"short_name": "45204",
|
163
|
-
"types": [
|
164
|
-
"postal_code"
|
165
|
-
]
|
166
|
-
},
|
167
|
-
{
|
168
|
-
"long_name": "Cincinnati",
|
169
|
-
"short_name": "Cincinnati",
|
170
|
-
"types": [
|
171
|
-
"locality",
|
172
|
-
"political"
|
173
|
-
]
|
174
|
-
},
|
175
|
-
{
|
176
|
-
"long_name": "Hamilton County",
|
177
|
-
"short_name": "Hamilton County",
|
178
|
-
"types": [
|
179
|
-
"administrative_area_level_2",
|
180
|
-
"political"
|
181
|
-
]
|
182
|
-
},
|
183
|
-
{
|
184
|
-
"long_name": "Ohio",
|
185
|
-
"short_name": "OH",
|
186
|
-
"types": [
|
187
|
-
"administrative_area_level_1",
|
188
|
-
"political"
|
189
|
-
]
|
190
|
-
},
|
191
|
-
{
|
192
|
-
"long_name": "United States",
|
193
|
-
"short_name": "US",
|
194
|
-
"types": [
|
195
|
-
"country",
|
196
|
-
"political"
|
197
|
-
]
|
198
|
-
}
|
199
|
-
],
|
200
|
-
"formatted_address": "Cincinnati, OH 45204, USA",
|
201
|
-
"geometry": {
|
202
|
-
"bounds": {
|
203
|
-
"northeast": {
|
204
|
-
"lat": 39.1251898,
|
205
|
-
"lng": -84.539683
|
206
|
-
},
|
207
|
-
"southwest": {
|
208
|
-
"lat": 39.073286,
|
209
|
-
"lng": -84.62870989999999
|
210
|
-
}
|
211
|
-
},
|
212
|
-
"location": {
|
213
|
-
"lat": 39.0930395,
|
214
|
-
"lng": -84.56676650000001
|
215
|
-
},
|
216
|
-
"location_type": "APPROXIMATE",
|
217
|
-
"viewport": {
|
218
|
-
"northeast": {
|
219
|
-
"lat": 39.1251898,
|
220
|
-
"lng": -84.539683
|
221
|
-
},
|
222
|
-
"southwest": {
|
223
|
-
"lat": 39.073286,
|
224
|
-
"lng": -84.62870989999999
|
225
|
-
}
|
226
|
-
}
|
227
|
-
},
|
228
|
-
"place_id": "ChIJjYEP0hK2QYgRTJoYykoQeqw",
|
229
|
-
"postcode_localities": [
|
230
|
-
"Cincinnati",
|
231
|
-
"Queen City Square"
|
232
|
-
],
|
233
|
-
"types": [
|
234
|
-
"postal_code"
|
235
|
-
]
|
236
|
-
}
|
237
|
-
'''
|
238
|
-
components = response[0]['address_components']
|
239
|
-
types = response[0]['types']
|
240
|
-
location = response[0]['geometry']['location']
|
241
|
-
postcode_localities = response[0].get('postcode_localities', None)
|
242
|
-
|
243
|
-
data = { 'city': None, 'state': None, 'postcode': None }
|
244
|
-
data['lat'] = location['lat']
|
245
|
-
data['lng'] = location['lng']
|
246
|
-
|
247
|
-
# when checking the response for a zipcode verify the city name is in the list of localities
|
248
|
-
if 'postal_code' in types and postcode_localities and city:
|
249
|
-
matches = [l for l in components if (
|
250
|
-
'postal_localities' in l.get('types') and
|
251
|
-
(l.short_name.lower() == city.lower() or l.long_name.lower() == city.lower())
|
252
|
-
)]
|
253
|
-
city_present_in_postcode_localities = (city in postcode_localities)
|
254
|
-
|
255
|
-
if not matches and not city_present_in_postcode_localities:
|
256
|
-
return None
|
257
|
-
|
258
|
-
for component in components:
|
259
|
-
if 'locality' in component['types']:
|
260
|
-
data['city'] = component['short_name']
|
261
|
-
elif 'administrative_area_level_1' in component['types']:
|
262
|
-
data['state'] = component['short_name']
|
263
|
-
elif 'postcode' in component['types'] or 'postal_code' in component['types']:
|
264
|
-
data['postcode'] = component['short_name']
|
265
|
-
elif 'country' in component['types']:
|
266
|
-
data['country'] = component['short_name']
|
267
|
-
|
268
|
-
return data
|
269
|
-
|
270
173
|
gmaps = googlemaps.Client(key=app_config.GOOGLE_API_KEY)
|
271
174
|
response = gmaps.geocode(loc_str)
|
272
175
|
|
@@ -282,20 +185,7 @@ def __get_google_location(city, state, zipcode, country, logger):
|
|
282
185
|
logger.warning(f"Cannot select a single address from multiple for {loc_str}.")
|
283
186
|
return None
|
284
187
|
response = [selected_address]
|
285
|
-
|
286
|
-
data = __parse_response(response)
|
287
|
-
|
288
|
-
# For some locals like neighborhood google does not return postal_code
|
289
|
-
## if zipcode is present run it only and verify against city
|
290
|
-
if data and not data['postcode']:
|
291
|
-
if zipcode:
|
292
|
-
response = gmaps.geocode(zipcode)
|
293
|
-
else:
|
294
|
-
response = gmaps.reverse_geocode((data['lat'], data['lng']))
|
295
|
-
post_code_data = __parse_response(response)
|
296
|
-
data['postcode'] = post_code_data['postcode'] if post_code_data else None
|
297
|
-
if data['postcode']:
|
298
|
-
__cache_location(city, state, zipcode, data, logger)
|
188
|
+
data = __parse_response(response, city)
|
299
189
|
return data
|
300
190
|
except googlemaps.exceptions.Timeout as e:
|
301
191
|
msg = "geolocate.__get_google_location - Location lookup timed out {0}, {1}, {2}: {3}".format(city, state, zipcode, e)
|
@@ -314,6 +204,123 @@ def __get_google_location(city, state, zipcode, country, logger):
|
|
314
204
|
|
315
205
|
return None
|
316
206
|
|
207
|
+
def __parse_response(response, city):
|
208
|
+
if not response or len(response) == 0:
|
209
|
+
return None
|
210
|
+
'''
|
211
|
+
Sample response of Google Maps API for address: Cincinati, OH, 45204
|
212
|
+
{
|
213
|
+
"address_components": [
|
214
|
+
{
|
215
|
+
"long_name": "45204",
|
216
|
+
"short_name": "45204",
|
217
|
+
"types": [
|
218
|
+
"postal_code"
|
219
|
+
]
|
220
|
+
},
|
221
|
+
{
|
222
|
+
"long_name": "Cincinnati",
|
223
|
+
"short_name": "Cincinnati",
|
224
|
+
"types": [
|
225
|
+
"locality",
|
226
|
+
"political"
|
227
|
+
]
|
228
|
+
},
|
229
|
+
{
|
230
|
+
"long_name": "Hamilton County",
|
231
|
+
"short_name": "Hamilton County",
|
232
|
+
"types": [
|
233
|
+
"administrative_area_level_2",
|
234
|
+
"political"
|
235
|
+
]
|
236
|
+
},
|
237
|
+
{
|
238
|
+
"long_name": "Ohio",
|
239
|
+
"short_name": "OH",
|
240
|
+
"types": [
|
241
|
+
"administrative_area_level_1",
|
242
|
+
"political"
|
243
|
+
]
|
244
|
+
},
|
245
|
+
{
|
246
|
+
"long_name": "United States",
|
247
|
+
"short_name": "US",
|
248
|
+
"types": [
|
249
|
+
"country",
|
250
|
+
"political"
|
251
|
+
]
|
252
|
+
}
|
253
|
+
],
|
254
|
+
"formatted_address": "Cincinnati, OH 45204, USA",
|
255
|
+
"geometry": {
|
256
|
+
"bounds": {
|
257
|
+
"northeast": {
|
258
|
+
"lat": 39.1251898,
|
259
|
+
"lng": -84.539683
|
260
|
+
},
|
261
|
+
"southwest": {
|
262
|
+
"lat": 39.073286,
|
263
|
+
"lng": -84.62870989999999
|
264
|
+
}
|
265
|
+
},
|
266
|
+
"location": {
|
267
|
+
"lat": 39.0930395,
|
268
|
+
"lng": -84.56676650000001
|
269
|
+
},
|
270
|
+
"location_type": "APPROXIMATE",
|
271
|
+
"viewport": {
|
272
|
+
"northeast": {
|
273
|
+
"lat": 39.1251898,
|
274
|
+
"lng": -84.539683
|
275
|
+
},
|
276
|
+
"southwest": {
|
277
|
+
"lat": 39.073286,
|
278
|
+
"lng": -84.62870989999999
|
279
|
+
}
|
280
|
+
}
|
281
|
+
},
|
282
|
+
"place_id": "ChIJjYEP0hK2QYgRTJoYykoQeqw",
|
283
|
+
"postcode_localities": [
|
284
|
+
"Cincinnati",
|
285
|
+
"Queen City Square"
|
286
|
+
],
|
287
|
+
"types": [
|
288
|
+
"postal_code"
|
289
|
+
]
|
290
|
+
}
|
291
|
+
'''
|
292
|
+
components = response[0]['address_components']
|
293
|
+
types = response[0]['types']
|
294
|
+
location = response[0]['geometry']['location']
|
295
|
+
postcode_localities = response[0].get('postcode_localities', None)
|
296
|
+
|
297
|
+
data = {'city': None, 'state': None, 'postcode': None}
|
298
|
+
data['lat'] = location['lat']
|
299
|
+
data['lng'] = location['lng']
|
300
|
+
|
301
|
+
# when checking the response for a zipcode verify the city name is in the list of localities
|
302
|
+
if 'postal_code' in types and postcode_localities and city:
|
303
|
+
matches = [l for l in components if (
|
304
|
+
'postal_localities' in l.get('types') and
|
305
|
+
(l.short_name.lower() == city.lower() or l.long_name.lower() == city.lower())
|
306
|
+
)]
|
307
|
+
city_present_in_postcode_localities = (city in postcode_localities)
|
308
|
+
|
309
|
+
if not matches and not city_present_in_postcode_localities:
|
310
|
+
return None
|
311
|
+
|
312
|
+
for component in components:
|
313
|
+
if 'locality' in component['types']:
|
314
|
+
data['city'] = component['short_name']
|
315
|
+
elif 'administrative_area_level_1' in component['types']:
|
316
|
+
data['state'] = component['short_name']
|
317
|
+
elif 'postcode' in component['types'] or 'postal_code' in component['types']:
|
318
|
+
data['postcode'] = component['short_name']
|
319
|
+
elif 'country' in component['types']:
|
320
|
+
data['country'] = component['short_name']
|
321
|
+
|
322
|
+
return data
|
323
|
+
|
317
324
|
def __cache_location(city, state, zipcode, location_data, logger):
|
318
325
|
location_string = __get_location_string(city, state, zipcode)
|
319
326
|
location_db_conn.set(location_string, str(location_data))
|
@@ -404,3 +411,20 @@ def __select_address(city, state, address_list):
|
|
404
411
|
and parsed_city_and_state['state'].strip().lower() == state.strip().lower():
|
405
412
|
return parsed_city_and_state['address']
|
406
413
|
return None
|
414
|
+
|
415
|
+
def __get_matching_location_from_cache(city, state, lat, lng, logger):
|
416
|
+
matching_location = None
|
417
|
+
try:
|
418
|
+
if city and state and lat and lng:
|
419
|
+
key = __get_location_string(city, state, None)
|
420
|
+
pattern = f'{key}*'
|
421
|
+
matching_keys = location_db_conn.keys(pattern)
|
422
|
+
if matching_keys:
|
423
|
+
for matching_key in matching_keys:
|
424
|
+
location = literal_eval(location_db_conn.get(matching_key).decode('utf-8'))
|
425
|
+
if location.get('lat') == lat and location.get('lng') == lng and location.get('postcode'):
|
426
|
+
matching_location = location
|
427
|
+
break
|
428
|
+
except Exception as e:
|
429
|
+
logger.warn("geolocate.__get_matching_location_from_cache: Failed: ", e)
|
430
|
+
return matching_location
|
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
|
|
3
3
|
setup(
|
4
4
|
name='cc_py_commons',
|
5
5
|
description='Common code for microservices',
|
6
|
-
version='0.5.
|
6
|
+
version='0.5.15',
|
7
7
|
url='https://github.com/Cargo-Chief/py-commons',
|
8
8
|
author='CargoChief',
|
9
9
|
author_email='engineering@cargochief.com',
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/carriers/account_carrier_map_schema.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/loads/freighthub_contact_schema.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/analytics/analytics_event.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/booking_agent/__init__.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/booking_agent/accept_bid.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/booking_agent/cancel_bid.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/booking_agent/constants.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/booking_agent/counter_bid.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/booking_agent/decline_bid.py
RENAMED
File without changes
|
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/booking_agent/get_quote.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/booking_agent/update_bid.py
RENAMED
File without changes
|
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/c4/amazon_session_token.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/c4/get_account_settings.py
RENAMED
File without changes
|
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/c4/get_users_for_account.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/c4/refresh_amazon_token.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/carrier_hub/__init__.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/carrier_hub/get_carrier.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/carrier_hub/list_carriers.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/carrier_hub/list_contacts.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/carrier_hub/update_contact.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/freight_hub/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/db/delete_table.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/get_import_stat.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/get_lane_price.py
RENAMED
File without changes
|
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/list_clients.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/post_import_stat.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/mercury/update_import_stat.py
RENAMED
File without changes
|
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/services/slack/send_slack_message.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/sns/import_movements_notification.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/sns/parsed_carrier_notification.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/sqs/booking_assistant_flow_event.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/transactions/equipment_clas_schema.py
RENAMED
File without changes
|
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/transactions/equipment_mapping.py
RENAMED
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/transactions/equipment_mapping_schema.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/transactions/transaction_schema.py
RENAMED
File without changes
|
File without changes
|
{cc_py_commons-0.5.13 → cc_py_commons-0.5.15}/cc_py_commons/utils/bulk_lane_price_result_utils.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|