from bs4 import BeautifulSoup


def get_text_from_json(json_file):
    """
    Grabs the text of an opinion file from the json file
    """
    # get html from json file
    # check each of these keys for the case text
    html = ''
    keys_to_try = ['html', 'plain_text', 'html_with_citations',
                   'html_lawbox', 'html_columbia']
    for key in keys_to_try:
        contents = json_file[key]

        # if the contents is not empty then extract the text and move on
        if (contents is not None) and len(contents) > 0:
            html = contents
            break

    # parse html with bs4
    parsed_html = BeautifulSoup(html, 'html.parser')

    # grab the text of the opinion
    return parsed_html.get_text()