def read_csv(fpath, encoding='utf-8'):
    if not os.path.isfile(fpath):
        download_files()
    if six.PY2:  # pragma: no cover
        with open(fpath, 'r') as f:
            reader = cdr(f, encoding=encoding)
            data = [row for row in reader]
            return reader.fieldnames, data
    else:  # pragma: no cover
        with open(fpath, newline='', encoding=encoding) as f:
            reader = cdr(f)
            data = [row for row in reader]
            return reader.fieldnames, data
def read_py3(filename):  # pragma: no cover
    try:
        with open(filename, newline='', encoding='utf-8-sig') as f:
            reader = cdr(f)
            data = [row for row in reader]
    except UnicodeDecodeError:
        try:
            with open(filename, newline='', encoding='windows-1252') as f:
                reader = cdr(f)
                data = [row for row in reader]
        except Exception:
            data = [{}]
    except Exception:
        data = [{}]
    return data
def read_in_s3(url):
    response = requests.get(url)
    if six.PY2:  # pragma: no cover
        f = io.BytesIO(response.text.encode('utf-8'))
    else:  # pragma: no cover
        f = io.StringIO(response.text)
    reader = cdr(f)
    data = [row for row in reader]
    return data
Exemple #4
0
def load_perkins_data(csvfile):
    with open(csvfile, 'r') as f:
        reader = cdr(f)
        return [row for row in reader]