import requests


def fetchAPI(public_api):
    """
    Fetches price data from centralized public web API endpoints
    Returns: (str) ticker price from public exchange web APIs
    Input: (list of str) public api endpoint with any necessary json parsing keywords
    """
    try:
        # Parse list input
        endpoint = public_api[0]
        parsers = public_api[1:]

        # Request JSON from public api endpoint
        r = requests.get(endpoint)
        json_ = r.json()

        # Parse through json with pre-written keywords
        for keyword in parsers:
            json_ = json_[keyword]

        # return price (last remaining element of the json)
        price = json_
        return float(price)
    except:
        response = 0
        print("API ERROR", public_api[0])