def selectDir(): global uploadRoot index.okLabel("UFno") uploadRoot = tk.filedialog.askdirectory( ) # 資料夾本人路徑 ex.C:/Users/Evolutivelabs/Roaming/Downloads/2000 index.root("UF", uploadRoot) index.okBtn("UF", uploadRoot)
def writeFile(): data = DataFrame(allData) data.to_excel(uploadRoot + r"/" + fileName, encoding='utf8', index=False, header=False) index.okLabel("UFok") print("ok")
def main(): global SPREADSHEET_ID, deviceWhich_RANGE_NAME, designer_RANGE_NAME, color_RANGE_NAME, sheet creds = None # token.pickle stores the user's access and refresh tokens, and is created automatically if os.path.exists('token.pickle'): with open('token.pickle', 'rb') as token: creds = pickle.load(token) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: creds.refresh(Request()) else: flow = InstalledAppFlow.from_client_secrets_file('client_secret.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run with open('token.pickle', 'wb') as token: pickle.dump(creds, token) service = build('sheets', 'v4', credentials=creds) # Call the Sheets API sheet = service.spreadsheets() # =============================== upload file用 =============================== # Var.needColor = [] Var.allColor = [] Var.allBrand = [] Var.ChooseSheet = "" Var.deviceB2C = [] Var.deviceB2B = [] Var.deviceKroma = [] Var.deviceWhich = [] Var.allBrandB2C = [] Var.allBrandB2B = [] Var.allBrandKroma = [] Var.SEcountry = ['tw', 'jp', 'other'] sheetUF.mainUF() index.okLabel("UFno") # =============================== delete color 用 =============================== # Var.needColor = [] Var.allColor = [] Var.preOrder = [] Var.preOrderDevice = [] Var.preOrderDate = [] Var.Allcountry = ['TW', 'IO', 'EU', 'FR', 'DE', 'JP', 'ES'] Var.changePriceMsg = "" Var.putPreorderMsg = "" sheetDC.mainDC()
def selectFile(): Var.fileORdir = 1 global inputfile, dirRoot inputfile = tk.filedialog.askopenfilename() splitRoot = os.path.split(inputfile) dirRoot = splitRoot[0] fileRoot = splitRoot[1] index.root("DC", fileRoot) index.okLabel("DCno") index.okBtn("DC",fileRoot)
def selectDir(): Var.fileORdir = 2 global dirRoot, files files = [] dirRoot = tk.filedialog.askdirectory() # 資料夾本人路徑 ex.C:/Users/Evolutivelabs/Roaming/Downloads/2000 allfiles = os.listdir(dirRoot) # 資料夾內所有檔案 for file in allfiles: if file.endswith(".csv"): files.append(file) print(files) index.root("DC", dirRoot) index.okLabel("DCno") index.okBtn("DC",dirRoot) allInOne()
def DeletingColor(colSKU): # 先讀csv檔進來 Var.changePrice = False Var.putPreorder = False Var.changePriceMsg = "" Var.putPreorderMsg = "" try: # 單一檔案的 if Var.fileORdir == 1: print(inputfile) input = open(inputfile, 'r', encoding="utf-8", newline='') # 資料夾的 if Var.fileORdir == 2: print(dirRoot + r"/withoutTrim.csv") input = open(dirRoot + r"/withoutTrim.csv", 'r', encoding="utf-8", newline='') output = open(dirRoot + "/" + outputfile + r".csv", 'w', encoding="utf-8", newline='') writer = csv.writer(output) for i, row in enumerate(csv.reader(input)): if row != ['\x1a'] and i == 0: # 為了把第一行header寫進去 writer.writerow(row) # 判斷是不是給shopify/stock if "sku" not in row[colSKU].lower(): print("你是不是選錯了阿(shopify or stock)") index.okLabel("Error") if os.path.exists(dirRoot + "/" + outputfile + r".csv"): output.close() os.remove(dirRoot + "/" + outputfile + r".csv") return # 開始把要的顏色一行行寫進去: row[colSKU] = 'SSA03173E7-OA06' elif row != ['\x1a']: pattern_device = '[0-9]{5}[A-Z0-9]{2,3}-' PreDevice = re.search(pattern_device, row[colSKU]).group() pattern_SKU = '-[A-Z]*' designSKU = re.search(pattern_SKU, row[colSKU]).group() # 圖號 # 如果是需要的顏色 if PreDevice in Var.needColor: # 如果有預購狀態 row[8] and 是選擇上傳shopify的 if Var.ShopifyStock == 1 and PreDevice in Var.preOrderDevice: PutPreorder(PreDevice, row) # 如果SKU圖號是要改價錢的設計師 if Var.ShopifyStock == 1 and designSKU in Var.priceFR[0]: pattern_product = '^[A-Z3]{2,3}' productLine = re.search(pattern_product, row[colSKU]).group() # SSA/NPB/3PB/NX/EC/ABA newPrice(designSKU,productLine,row) writer.writerow(row) # 如果有改價錢要跳通知 if Var.changePrice: index.infoMsg(Var.changePriceMsg) # 如果有改價錢要跳通知 if Var.putPreorder: index.infoMsg(Var.putPreorderMsg) index.okLabel("DCok") input.close() except Exception as e: print(e) index.okLabel("Error") if os.path.exists(dirRoot + "/" + outputfile + r".csv"): output.close() os.remove(dirRoot + "/" + outputfile + r".csv")