Spaces:
Build error
Build error
File size: 1,358 Bytes
606ca5f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | import pickle
import pandas as pd
import os.path
DATA_DIR = "_data"
def get_data_dir():
return DATA_DIR
def set_data_dir(data_dir):
global DATA_DIR
DATA_DIR = data_dir
def get_products_dir():
products_dir = os.path.join(get_data_dir(), "products")
if not os.path.exists(products_dir):
os.makedirs(products_dir)
return products_dir
def get_results_dir():
results_dir = os.path.join(get_data_dir(), "results")
if not os.path.exists(results_dir):
os.makedirs(results_dir)
return results_dir
def get_temp_dir():
temp_dir = os.path.join(get_data_dir(), "temp")
if not os.path.exists(temp_dir):
os.makedirs(temp_dir)
return temp_dir
def load_df_from_file(filepath):
if not os.path.isfile(filepath):
return None
return pd.read_pickle(filepath)
def save_df_to_file(df, filepath, save_csv_copy = False):
df.to_pickle(filepath)
if save_csv_copy:
fullfn_csv = filepath + '.csv'
df.to_csv(fullfn_csv, encoding="utf-8")
def load_dict_from_file(filepath):
if not os.path.isfile(filepath):
return None
with open(filepath, 'rb') as fn:
str = fn.read()
return pickle.loads(str)
def save_dict_to_file(dict, filepath):
with open(filepath, 'wb') as fn:
str = pickle.dumps(dict)
fn.write(str)
|