import requests


def get_dois(doi, citing=True):
    """
    Get the dois of papers citing or cited by a given doi using opencitations.net

    Silvio Peroni, David Shotton (2020). OpenCitations, an infrastructure
    organization for open scholarship. Quantitative Science Studies, 1(1):
    428-444. https://doi.org/10.1162/qss_a_00023


    Inputs
    ------
    doi : string
        The DOI of the paper whose citing DOIs or references you want to list.
    citing : bool,
        Wether to get the DOIs citing the given DOI or cited by the given DOI (default: True).

    Outputs
    -------
    citing_dois : list of strings
        List of DOIs of papers that cite the given DOI.
    """
    type = "citations" if citing else "references"
    key = "citing" if citing else "cited"
    url = f"https://opencitations.net/index/coci/api/v1/{type}/{doi}"
    items = requests.get(url).json()
    found_dois = []
    if items:  # if opencitations.net lists citing items
        for item in items:
            found_dois.append(item[key])
    return found_dois