walmart script
This commit is contained in:
63
Scripts/WalmartExcel/walmart.py
Normal file
63
Scripts/WalmartExcel/walmart.py
Normal file
@ -0,0 +1,63 @@
|
||||
import os
|
||||
import sys
|
||||
from datetime import date
|
||||
import glob
|
||||
import shutil
|
||||
import csv
|
||||
import pandas as pd
|
||||
|
||||
rootdir = "/Users/normrasmussen/Documents/Resources/Walmart/"
|
||||
downloadir = "/Users/normrasmussen/Google Drive/My Drive/Shared with Clients/Walmart/"
|
||||
basefile = "WalmartBase.xlsx"
|
||||
|
||||
def copytemplate(rootdir, basefile):
|
||||
today = date.today()
|
||||
today = today.strftime("%m.%d.%Y")
|
||||
template = rootdir+basefile
|
||||
todayFile = f"Walmart-{today}.xlsx"
|
||||
if os.path.exists(rootdir):
|
||||
shutil.copy2(template, rootdir+todayFile)
|
||||
#dirfiles = os.listdir(rootdir)
|
||||
#print(dirfiles)
|
||||
currentDash = rootdir+f"Walmart-{today}.xlsx"
|
||||
print(currentDash)
|
||||
findlatestExport(currentDash)
|
||||
|
||||
def findlatestExport(currentDash):
|
||||
listfiles = glob.glob(downloadir + '*.xlsx')
|
||||
latestdownload = max(listfiles, key=os.path.getctime)
|
||||
print(latestdownload)
|
||||
copytoDash(latestdownload, currentDash)
|
||||
|
||||
def copytoDash(latestdownload, currentDash):
|
||||
readExport = pd.read_excel(latestdownload, index_col=False)
|
||||
readExport.drop(
|
||||
readExport.filter(
|
||||
regex="Unname"
|
||||
),axis=1,
|
||||
inplace=True)
|
||||
copiedData = readExport.copy()
|
||||
#with pd.ExcelWriter("")
|
||||
|
||||
def bringtoExcel(latestdownload, currentDash):
|
||||
with pd.ExcelWriter(
|
||||
currentDash,
|
||||
mode="a",
|
||||
engine="openpyxl",
|
||||
if_sheet_exists="overlay",
|
||||
) as writer:
|
||||
copiedData.to_excel(
|
||||
writer,
|
||||
sheet_name="Data",
|
||||
index=False,
|
||||
)
|
||||
# cleanitUp(currentDash)
|
||||
|
||||
def cleanitUp(currentDash):
|
||||
cleanExcel = pd.read_excel(currentDash, sheet_name="Data", index_col=None)
|
||||
cleanExcel.columns.values[0] = "tmp"
|
||||
cleanExcel.drop(columns="tmp", axis=1, inplace=True)
|
||||
print(cleanExcel)
|
||||
|
||||
if __name__ == "__main__":
|
||||
copytemplate(rootdir, basefile)
|
||||
Reference in New Issue
Block a user