MultiplayerAiReco / course_project /data_persistence.py
Javier Real
Progress
73969b9
raw
history blame contribute delete
986 Bytes
import pickle
import os
DATABASE_LOCATION = "course_project/database/"
MOVIES_BK_FILE_LOCATION = DATABASE_LOCATION + "provisional_database_simulation.pkl"
MOVIES_BK_FILE_TRANSFORMED_LOCATION = DATABASE_LOCATION + "provisional_database_transformed.pkl"
def save_pickle(df, filename):
with open(filename, 'wb') as f:
pickle.dump(df, f)
def read_pickle(filename):
with open(filename, 'rb') as f:
df = pickle.load(f)
return df
def save_db(series_to_store):
save_pickle(series_to_store, MOVIES_BK_FILE_LOCATION)
def get_db():
if os.path.exists(MOVIES_BK_FILE_LOCATION):
return read_pickle(MOVIES_BK_FILE_LOCATION)
else:
return None
def save_transformed_db(series_to_store):
save_pickle(series_to_store, MOVIES_BK_FILE_TRANSFORMED_LOCATION)
def get_transformed_db():
if os.path.exists(MOVIES_BK_FILE_TRANSFORMED_LOCATION):
return read_pickle(MOVIES_BK_FILE_TRANSFORMED_LOCATION)
else:
return None