import requests
import time


def render_analysis(response, operation_url, headers):
    """
    This function waits for the analysis of the response image,
    so it runs a loop until the text detection is complete
    
    Arguments:
        response {Object} -- The response passed
        operation_url {String} -- The Operation url obtained from response

    Returns:
        [json] : The analysis json containing the detected text
    """


    analysis = {}
    poll = True
    while (poll):
        response_final = requests.get(
            response.headers["Operation-Location"], headers=headers)
        analysis = response_final.json()
        time.sleep(1)
        if ("recognitionResult" in analysis):
            poll= False 
        if ("status" in analysis and analysis['status'] == 'Failed'):
            poll= False
    return(analysis)