Work with Cvent API bug fix related to rate limit.
This commit is contained in:
14
app/main.py
14
app/main.py
@@ -374,13 +374,13 @@ origins = [
|
|||||||
|
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=origins,
|
allow_origins = origins,
|
||||||
allow_origin_regex='https://.*\.oneskyit\.com',
|
allow_origin_regex = 'https://.*\.oneskyit\.com',
|
||||||
allow_credentials=True,
|
allow_credentials = True,
|
||||||
allow_methods=['*'],
|
allow_methods = ['*'],
|
||||||
allow_headers=['*'],
|
allow_headers = ['*'],
|
||||||
#expose_headers=[],
|
#expose_headers = [],
|
||||||
#max_age=600,
|
#max_age = 600,
|
||||||
)
|
)
|
||||||
# END: CORS
|
# END: CORS
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from app.methods.membership_person_methods import create_membership_person_obj,
|
|||||||
|
|
||||||
app = {}
|
app = {}
|
||||||
app['client_id'] = '0oalt6dz82oSbN9ok1t7' # From Cvent Developer Portal
|
app['client_id'] = '0oalt6dz82oSbN9ok1t7' # From Cvent Developer Portal
|
||||||
app['secret'] = 'gQY96qffZAuB_44k73C_hn_MHeByBS8LXHj1vPRm' # From Cvent Developer
|
app['secret'] = 'gQY96qffZAuB_44k73C_hn_MHeByBS8LXHj1vPRm' # From Cvent Developer Portal
|
||||||
|
|
||||||
api = {}
|
api = {}
|
||||||
api['base_url'] = 'https://api-platform.cvent.com/ea' # Including /ea as the Cvent version. EA = Early Access
|
api['base_url'] = 'https://api-platform.cvent.com/ea' # Including /ea as the Cvent version. EA = Early Access
|
||||||
@@ -109,7 +109,7 @@ def get_contact_custom_field_list(api):
|
|||||||
# Updated 2022-01-31
|
# Updated 2022-01-31
|
||||||
@logger_reset
|
@logger_reset
|
||||||
def get_contact_list(external_id: str=None, email: str=None):
|
def get_contact_list(external_id: str=None, email: str=None):
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
get_access_token()
|
get_access_token()
|
||||||
@@ -122,18 +122,38 @@ def get_contact_list(external_id: str=None, email: str=None):
|
|||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
if external_id:
|
if external_id:
|
||||||
|
log.info(f'Looking up Cvent Contcat with External ID: {external_id}')
|
||||||
params['filter'] = f"deleted eq 'False' and customField.609ab766-7d79-4a9d-a72c-f126412659ee eq '{external_id}'"
|
params['filter'] = f"deleted eq 'False' and customField.609ab766-7d79-4a9d-a72c-f126412659ee eq '{external_id}'"
|
||||||
elif email:
|
elif email:
|
||||||
|
log.info(f'Looking up Cvent Contcat with Email: {email}')
|
||||||
params['filter'] = f"deleted eq 'False' and email eq '{email}'"
|
params['filter'] = f"deleted eq 'False' and email eq '{email}'"
|
||||||
elif external_id is None:
|
elif external_id is None:
|
||||||
|
log.info(f'Looking up Cvent Contact(s) with empty Cvent custom field for external ID.')
|
||||||
params['filter'] = f"deleted eq 'False' and customField.609ab766-7d79-4a9d-a72c-f126412659ee lt '1'"
|
params['filter'] = f"deleted eq 'False' and customField.609ab766-7d79-4a9d-a72c-f126412659ee lt '1'"
|
||||||
else:
|
else:
|
||||||
|
log.info(f'Looking up Cvent Contact(s) that have not been marked as deleted.')
|
||||||
params['filter'] = f"deleted eq 'False'"
|
params['filter'] = f"deleted eq 'False'"
|
||||||
|
|
||||||
resp = requests.get(url=uri, headers=api['headers'], params=params)
|
try_request = True
|
||||||
|
limit = 0
|
||||||
|
while try_request and limit < 3:
|
||||||
|
limit = limit + 1
|
||||||
|
resp = requests.get(url=uri, headers=api['headers'], params=params)
|
||||||
|
|
||||||
response_data = resp.json()
|
response_data = resp.json()
|
||||||
log.debug(json.dumps(response_data, indent=2, default=str))
|
log.debug(json.dumps(response_data, indent=2, default=str))
|
||||||
|
|
||||||
|
if 'message' in response_data and response_data['message'] == 'Too Many Requests':
|
||||||
|
log.warning('Hit Cvent rate limit. Sleeping for .5 seconds...')
|
||||||
|
time.sleep(.5)
|
||||||
|
else:
|
||||||
|
if 'paging' in response_data:
|
||||||
|
current_token = response_data.get('paging').get('currentToken')
|
||||||
|
total_count = response_data.get('paging').get('totalCount')
|
||||||
|
log.info(f'Found {total_count} results from Cvent Contact list')
|
||||||
|
log.debug(json.dumps(response_data.get('paging'), indent=2, default=str))
|
||||||
|
|
||||||
|
try_request = False
|
||||||
|
|
||||||
if 'message' in response_data and response_data['message'] == 'Too Many Requests': return False
|
if 'message' in response_data and response_data['message'] == 'Too Many Requests': return False
|
||||||
|
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ async def get_person_w_external_id(
|
|||||||
log.info(f'Something went wrong while trying to create or update the person in Aether based on Cvent data. Cvent (Person) Contact ID: {cvent_person_contact_id}')
|
log.info(f'Something went wrong while trying to create or update the person in Aether based on Cvent data. Cvent (Person) Contact ID: {cvent_person_contact_id}')
|
||||||
return mk_resp(data=None, status_code=400, response=commons.response,status_message=f'Something went wrong while trying to create or update the person in Aether based on Cvent data. Cvent (Person) Contact ID: {cvent_person_contact_id}') # Bad Request
|
return mk_resp(data=None, status_code=400, response=commons.response,status_message=f'Something went wrong while trying to create or update the person in Aether based on Cvent data. Cvent (Person) Contact ID: {cvent_person_contact_id}') # Bad Request
|
||||||
else:
|
else:
|
||||||
log.info(f'More than one result was returned with the external ID. External ID: {email}')
|
log.info(f'More than one result was returned with the external ID. External ID: {external_id}')
|
||||||
return mk_resp(data=None, status_code=400, response=commons.response) # Bad Request
|
return mk_resp(data=None, status_code=400, response=commons.response) # Bad Request
|
||||||
|
|
||||||
# ### SECTION ### Return successful results
|
# ### SECTION ### Return successful results
|
||||||
|
|||||||
Reference in New Issue
Block a user