import requests


def get_full_iri(obo_id):
    """
    Given an ontology id of the form X:01234, look up the full iri using the ebi ols
    :param obo_id: ontology identifier, e.g. HsapDv:0000087
    :type obo_id: string
    :return: full iri for the term, e.g. http://purl.obolibrary.org/obo/HsapDv_0000087
    :rtype: string
    """
    try:
        obo_id = obo_id.strip()
        ols_response = requests.get('http://www.ebi.ac.uk/ols/api/terms?obo_id={}'.format(obo_id))
        ols_json = ols_response.json()
        return ols_json['_embedded']['terms'][0]['iri']
    except KeyError:
        print('http://www.ebi.ac.uk/ols/api/terms?id={}'.format(obo_id))
        print("Could not find {}.".format(obo_id))
        return None
    except ConnectionError as e:
        print(e)
        print("Something went wrong while trying to fetch from api.")