def read_in_data(filename): """Read in a utf-8 CSV, as per our spec, or windows-1252 if we must.""" 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_csv(fpath, encoding='utf-8'): if not os.path.isfile(fpath): download_files() with open(fpath, newline='', encoding=encoding) as f: reader = cdr(f) data = [row for row in reader] return reader.fieldnames, data
def read_in_s3(url): response = requests.get(url) f = io.StringIO(response.text) reader = cdr(f) data = [row for row in reader] return data
def load_bls_data(csvfile): with open(csvfile, 'rU') as f: reader = cdr(f) return [row for row in reader]
def load_perkins_data(csvfile): with open(csvfile, 'r') as f: reader = cdr(f) return [row for row in reader]