Product_Matching / tmp /utils.py
Gainward777's picture
Update tmp/utils.py
d1698fd verified
raw
history blame
1.2 kB
import pandas as pd
from preprocess.utils.common.utils import get_delimiter
from glob import glob
import shutil
import os
def update_products_csv(new_csv_path, main_csv_path='/home/user/app/tmp/prod.csv'):
main_sep=get_delimiter(main_csv_path)
main_csv=pd.read_csv(main_csv_path, sep=main_sep)
new_sep=get_delimiter(new_csv_path)
new_csv=pd.read_csv(new_csv_path, sep=new_sep)
result=pd.concat([main_csv, new_csv]).drop_duplicates(subset='id', keep='last').reset_index(drop=True)
result.to_csv(main_csv_path, sep=main_sep, index=False)
def is_csv_exist(path):
file_list=glob(path+'/*.csv')
if len(file_list)>0:
return file_list[0]
else:
None
def uploader(new_path, main_dir='/home/user/app/tmp/prod.csv'):
main_path=is_csv_exist(main_dir)
if main_path==None:
new_path = shutil.move(new_path, main_dir)
return new_path
else:
update_products_csv(main_path, new_path)
return main_path
def remover():
#path=is_csv_exist('/home/user/app/tmp/prod.csv')
#if path!=None:
os.remove(os.getcwd()+'/tmp/prod.csv')
shutil.copy2('/home/user/app/tmp/service/prod.csv', '/home/user/app/tmp/prod.csv')