Created
February 15, 2024 18:14
-
-
Save aarmora/28ad0dde2ae9b3d8b89cf20d23f0eef7 to your computer and use it in GitHub Desktop.
Python retryId recursive funciton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import asyncio | |
async def retry_business_details(retry_id, retry_count=0, screenshot=False, ucc_data=None, street=None, city=None, zip_code=None): | |
url = f"https://apigateway.cobaltintelligence.com/v1/search?retryId={retry_id}" | |
if hasattr(self, 'targeted_environment'): | |
url = f"https://apigateway.cobaltintelligence.com/{self.targeted_environment}/search?retryId={retry_id}" | |
if screenshot: | |
url += '&screenshot=true' | |
headers = { | |
'x-api-key': self.api_key | |
} | |
response = requests.get(url, headers=headers) | |
# Functions timeout after 70 attempts | |
if retry_count > 70: | |
return {'message': 'Passed 70 attempts of retries. Something must have gone wrong. Sorry.'} | |
if response.json().get('status') == 'Incomplete': | |
print('Retrying. Total retry attempts', retry_count) | |
retry_count += 1 | |
# Item not ready yet | |
# We wait 10 seconds and then try again | |
await asyncio.sleep(10) | |
return await retry_business_details(retry_id, retry_count, screenshot, ucc_data, street, city, zip_code) | |
return response.json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment