import requests


def _get_bin_count(fpath, delimiter=',', encoding='ISO-8859-1'):
    """
    Gets the number of bins in the file.
    
    :param fpath: A path or url for the file (if a url it must 
        include `http`, and if a file path it must not contain 
        `http`).
    :type fpath: string
    :param delimiter: The delimiter between items in the file, 
        defaults to ','.
    :type delimiter: string
    :param encoding: The encoding for the file, defaults to 
        'ISO-8859-1'.
    :type encoding: string
    :return: The number of bins in the file.
    :rtype: int
    """
    bins = 0
    if 'http' in fpath:
        req = requests.get(fpath)

        for line in req.iter_lines():
            try:
                if float(line.decode(encoding).split(delimiter)[0]):
                    bins += 1
            except: pass
    else:
        with open(fpath, 'r', encoding=encoding) as f:
            for line in f:
                try:
                    if float(line.split(delimiter)[0]):
                        bins += 1
                except: pass

    return bins