def analyzer_api(url):
    """
    Analyze given `url` and return output as JSON.
    """
    response.content_type = JSON_MIME

    # handle cacheing
    ri = get_cached_or_new(url)

    try:

        if ri.is_old():
            logger.info("Running the analysis.")

            # forget the old one and create new request info - this prevents
            # conflict errors
            ri = get_cached_or_new(url, new=True)

            # run the processing
            ri.paralel_processing()

    except (requests.exceptions.Timeout, requests.ConnectionError) as e:
        error_msg = """
            Požadovanou stránku {url} nebylo možné stáhnout během {timeout}
            vteřin. Zkuste URL zadat s `www.`, či zkontrolovat funkčnost
            stránek.
            <span style="display: none">{message}</span>
        """
        error_msg = error_msg.format(
            url=url,
            timeout=REQUEST_TIMEOUT,
            message=str(e.message)
        )
        logger.error(error_msg)

        return {
            "status": False,
            "log": "",  # TODO: get real log
            "error": error_msg,
        }
    except Exception as e:
        error_msg = str(e.message) + "\n" + traceback.format_exc().strip()
        logger.error(error_msg)
        return {
            "status": False,
            "log": "ri.get_log()",
            "error": error_msg,
        }

    return {
        "status": True,
        "body": ri.to_dict(),
        "log": "ri.get_log()",
    }
def analyzer_api ( url ) : response . content_type = JSON_MIME ri = get_cached_or_new ( url ) try : if ri . is_old ( ) : logger . info ( "Running the analysis." ) ri = get_cached_or_new ( url , new = True ) ri . paralel_processing ( ) except ( requests . exceptions . Timeout , requests . ConnectionError ) as e : error_msg = """
            Požadovanou stránku {url} nebylo možné stáhnout během {timeout}
            vteřin. Zkuste URL zadat s `www.`, či zkontrolovat funkčnost
            stránek.
            <span style="display: none">{message}</span>
        """ error_msg = error_msg . format ( url = url , timeout = REQUEST_TIMEOUT , message = str ( e . message ) ) logger . error ( error_msg ) return { "status" : False , "log" : "" , "error" : error_msg , } except Exception as e : error_msg = str ( e . message ) + "\n" + traceback . format_exc ( ) . strip ( ) logger . error ( error_msg ) return { "status" : False , "log" : "ri.get_log()" , "error" : error_msg , } return { "status" : True , "body" : ri . to_dict ( ) , "log" : "ri.get_log()" , }
Analyze given `url` and return output as JSON.