Exemplo n.º 1
0
def read_in_s3(url):
    data = [{}]
    response = requests.get(url)
    try:
        f = StringIO.StringIO(response.content)
        reader = cdr(f, encoding='utf-8-sig')
        data = [row for row in reader]
    except UnicodeDecodeError:
        f = StringIO.StringIO(response.content)
        reader = cdr(f, encoding='windows-1252')
        data = [row for row in reader]
    except:
        return data
    return data
Exemplo n.º 2
0
def read_in_s3(url):
    data = [{}]
    response = requests.get(url)
    try:
        f = StringIO.StringIO(response.content)
        reader = cdr(f, encoding='utf-8-sig')
        data = [row for row in reader]
    except UnicodeDecodeError:
        f = StringIO.StringIO(response.content)
        reader = cdr(f, encoding='windows-1252')
        data = [row for row in reader]
    except:
        return data
    return data
Exemplo n.º 3
0
def read_csv(fpath, encoding='utf-8'):
    if not os.path.isfile(fpath):
        download_files()
    with open(fpath, 'r') as f:
        reader = cdr(f, encoding=encoding)
        data = [row for row in reader]
        return reader.fieldnames, data
Exemplo n.º 4
0
def read_in_encoding(filename, encoding='windows-1252'):
    """Throw a lifeline if the college just exported from Excel"""
    try:
        with open(filename, 'r') as f:
            reader = cdr(f, encoding=encoding)
            data = [row for row in reader]
    except Exception:
        data = [{}]
    return data
Exemplo n.º 5
0
def read_in_encoding(filename, encoding='windows-1252'):
    """Throw a lifeline if the college just exported from Excel"""
    try:
        with open(filename, 'r') as f:
            reader = cdr(f, encoding=encoding)
            data = [row for row in reader]
    except Exception:
        data = [{}]
    return data
Exemplo n.º 6
0
def read_in_data(filename):
    """Reads in utf-8 CSV (as per our spec)"""
    try_encoding = False
    with open(filename, 'r') as f:
        try:
            reader = cdr(f, encoding='utf-8-sig')
            data = [row for row in reader]
        except UnicodeDecodeError:
            try_encoding = True
        except:
            data = [{}]
    if try_encoding:  # sigh
        data = read_in_encoding(filename)
    return data
Exemplo n.º 7
0
def read_in_data(filename):
    """Reads in utf-8 CSV (as per our spec)"""
    try_encoding = False
    with open(filename, 'r') as f:
        try:
            reader = cdr(f, encoding='utf-8-sig')
            data = [row for row in reader]
        except UnicodeDecodeError:
            try_encoding = True
        except:
            data = [{}]
    if try_encoding:  # sigh
        data = read_in_encoding(filename)
    return data
Exemplo n.º 8
0
def load_bls_data(csvfile):

    with open(csvfile, 'rU') as f:
        reader = cdr(f)
        return [row for row in reader]
Exemplo n.º 9
0
def load_perkins_data(csvfile):
    with open(csvfile, 'r') as f:
        reader = cdr(f)
        return [row for row in reader]