import requests


def retrieve_text(
        entry, 
        container_name,
        azure_storage_account_name="azureopendatastorage",
        azure_storage_sas_token="",
):
    """ Retrieve body text from article of interest.
    
    Args:
        entry (pd.Series): A single row from the dataframe (df.iloc[n]).
        container_name (str): Azure storage container name.
        azure_storage_account_name (str): Azure storage account name.
        azure_storage_sas_token (str): Azure storage SAS token.

    Results:
        text (str): Full text of the blob as a single string.
    """

    try:
        filename = entry["pdf_json_files"] or entry["pmc_json_files"]

        # Extract text
        uri = "https://{acct}.blob.core.windows.net/{container}/{filename}{sas}".format(
            acct=azure_storage_account_name,
            container=container_name,
            filename=filename,
            sas=azure_storage_sas_token
        )

        data = requests.get(uri, headers={"Content-type": "application/json"}).json()
        text = " ".join([paragraph["text"] for paragraph in data["body_text"]])

    except:
        text = ""

    return text