def getOrders(path, columns): with open(path) as file: prevRow = list() parsedRows = list() reader = csv.reader(file) next(reader) # skip header row data = sorted(reader, key=operator.itemgetter(0)) for row in data: if len(row) < 2 or (prevRow and row[0] == prevRow[0]): continue # skip if < 2 cols or same order as prev row # create a new ordered dictionary to hold the row info newRow = collections.OrderedDict.fromkeys(columns) newRow['companyCode'] = 112 # marvellous newRow['merchantID'] = 42 newRow['completeOrderReference'] = validate.clean(row[0]) newRow['shortOrderReference'] = validate.clean(row[0]) newRow["originFile"] = os.path.basename(path) newRow['fullName'] = validate.clean(row[17]) newRow['phoneNumber'] = validate.phone(row[7]) newRow['address1'] = validate.clean(row[18]) newRow['address2'] = validate.clean(row[19]) newRow['town'] = validate.clean(row[20]) newRow['packingSlip'] = 1 newRow['country'] = validate.country(validate.clean(row[23])) if not newRow['country']: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += 'Could not validate country: ' + row[23] errors.append(msg) continue newRow['region'] = validate.region(validate.clean(row[21]), newRow['country']) if not newRow['region']: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += 'Could not validate region: ' + row[21] errors.append(msg) continue newRow['postCode'] = validate.postCode(validate.clean(row[22]), newRow['country']) if not newRow['postCode']: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += 'Could not validate post code: ' + row[22] errors.append(msg) continue if len(columns) == len(newRow): parsedRows.append(list(newRow.values())) else: print("Oops, Restaurant order parser added a column") quit() prevRow = row print("\nImported " + str(len(parsedRows)) + " orders from Restaurant file '" + os.path.basename(path) + "'") return parsedRows
def post(self): user = ndb.Key('Person', users.get_current_user().user_id()).get() if user: if user.setup: self.error(403) self.response.write(['please refresh your page and try again.']) else: error = [] user.setup = True try: user.contact = validate.contact(self.request.get('contact')) except Exception, e: error.append(str(e)) try: user.country = validate.country(self.request.get('country')) except Exception, e: error.append(str(e)) try: user.pic = validate.user_pic(self.request.get('pic')) except Exception, e: error.append(str(e))
def getOrders(path, columns): with open(path) as file: reader = csv.reader(file) # create a CSV reader object parsedRows = list() # create a list to hold the new rows for row in reader: # create a new ordered dictionary to hold the row info newRow = collections.OrderedDict.fromkeys(columns) if len(row) < 2 or row[13] == "": continue # skip if < 2 cols or no sku newRow["companyCode"] = 113 newRow["completeOrderReference"] = validate.clean(row[0]) newRow["shortOrderReference"] = validate.clean(row[0]) newRow["originFile"] = os.path.basename(path) newRow["merchantID"] = 38 newRow["fullName"] = validate.clean(row[11] + " " + row[12]) newRow["phoneNumber"] = "".join([char for char in row[18] if str.isdigit(char)]) newRow["address1"] = validate.clean(row[13]) newRow["address2"] = validate.clean(row[14]) newRow["town"] = validate.clean(row[15]) newRow["packingSlip"] = 0 newRow["country"] = validate.country(validate.clean(row[18])) if not newRow["country"]: msg = newRow["completeOrderReference"] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += "Could not validate country: " + row[18] + "\n" errors.append(msg) continue newRow["region"] = validate.region(validate.clean(row[16]), newRow["country"]) if not newRow["region"]: msg = newRow["completeOrderReference"] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += "Could not validate region: " + row[16] + "\n" errors.append(msg) continue newRow["postCode"] = validate.postCode(validate.clean(row[17]), newRow["country"]) if not newRow["postCode"]: msg = newRow["completeOrderReference"] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += "Could not validate post code: " + row[17] + "\n" errors.append(msg) continue if len(columns) == len(newRow): parsedRows.append(list(newRow.values())) else: print("Oops StackSocial order parser added a column") quit() print("\nImported " + str(len(parsedRows)) + " orders from StackSocial file '" + os.path.basename(path) + "'") return parsedRows
def getOrders(path, columns): with open(path) as file: reader = csv.reader(file) # create a CSV reader object parsedRows = list() # create a list to hold the new rows for row in reader: # create a new ordered dictionary to hold the row info newRow = collections.OrderedDict.fromkeys(columns) if len(row) < 2 or row[13] == '': continue # skip if < 2 cols or no sku newRow['companyCode'] = 113 newRow["completeOrderReference"] = validate.clean(row[0]) newRow["shortOrderReference"] = validate.clean(row[0]) newRow["originFile"] = os.path.basename(path) newRow["merchantID"] = 38 newRow["fullName"] = validate.clean(row[11] + " " + row[12]) newRow["phoneNumber"] = "".join( [char for char in row[18] if str.isdigit(char)]) newRow["address1"] = validate.clean(row[13]) newRow['address2'] = validate.clean(row[14]) newRow["town"] = validate.clean(row[15]) newRow['packingSlip'] = 0 newRow["country"] = validate.country(validate.clean(row[18])) if not newRow['country']: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( path) + "' was skipped.\n" msg += 'Could not validate country: ' + row[18] + '\n' errors.append(msg) continue newRow["region"] = validate.region(validate.clean(row[16]), newRow['country']) if not newRow['region']: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( path) + "' was skipped.\n" msg += 'Could not validate region: ' + row[16] + '\n' errors.append(msg) continue newRow["postCode"] = validate.postCode(validate.clean(row[17]), newRow['country']) if not newRow['postCode']: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( path) + "' was skipped.\n" msg += 'Could not validate post code: ' + row[17] + '\n' errors.append(msg) continue if len(columns) == len(newRow): parsedRows.append(list(newRow.values())) else: print("Oops StackSocial order parser added a column") quit() print("\nImported " + str(len(parsedRows)) + " orders from StackSocial file '" + os.path.basename(path) + "'") return parsedRows
def getOrders(self, columns): with open(self.file) as file: prevRow = list() parsedRows = list() reader = csv.reader(file) next(reader) # skip header row for row in reader: if len(row) < 2 or (prevRow and row[0] == prevRow[0]): continue # skip if < 2 cols or same order as prev row # create a new ordered dictionary to hold the row info newRow = collections.OrderedDict.fromkeys(columns) # set company and market self.companyCode = row[2] self.marketId = row[0][:2] self.market = row[0][3:] newRow[ 'marketId'] = self.market # save market id for confirmations newRow['companyCode'] = self.companyCode newRow['merchantID'] = self.getMarketParam('merchantID') if not newRow['merchantID']: continue newRow['completeOrderReference'] = validate.clean(row[1]) newRow['shortOrderReference'] = validate.shortenPossibleAmazon( row[1]) newRow['fullName'] = validate.clean(row[3]) newRow["originFile"] = os.path.basename(self.file) newRow['phoneNumber'] = validate.phone(row[4]) newRow['address1'] = validate.clean(row[5]) newRow['address2'] = validate.clean(row[6]) newRow['town'] = validate.clean(row[7]) newRow['packingSlip'] = 1 newRow['country'] = validate.country(validate.clean(row[10])) if not newRow['country']: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( self.file) + "' was skipped.\n" msg += 'Could not validate country: ' + row[10] self.errors.add(msg) continue newRow['region'] = validate.region(validate.clean(row[8]), newRow['country']) if not newRow['region']: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( self.file) + "' was skipped.\n" msg += 'Could not validate region: ' + row[8] self.errors.add(msg) continue newRow['postCode'] = validate.postCode(validate.clean(row[9]), newRow['country']) if not newRow['postCode']: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( self.file) + "' was skipped.\n" msg += 'Could not validate post code: ' + row[9] self.errors.add(msg) continue if len(columns) == len(newRow): parsedRows.append(list(newRow.values())) else: print("Oops, standard order parser added a column") quit() prevRow = row print("\nImported " + str(len(parsedRows)) + " orders from " + self.market + " file '" + os.path.basename(self.file) + "'") return parsedRows
def getOrders(path, columns): with open(path) as file: prevRow = list() parsedRows = list() reader = csv.reader(file) next(reader) # skip header row for row in reader: if len(row) < 2 or (prevRow and row[0] == prevRow[0]): continue # skip if < 2 cols or same order as prev row # create a new ordered dictionary to hold the row info newRow = collections.OrderedDict.fromkeys(columns) newRow['companyCode'] = 112 # marvellous newRow['merchantID'] = 45 newRow['completeOrderReference'] = validate.clean(row[0]) newRow['shortOrderReference'] = validate.clean(row[0]) newRow["originFile"] = os.path.basename(path) newRow['fullName'] = validate.clean(row[5]) + ' ' + validate.clean( row[6]) newRow['phoneNumber'] = validate.phone(row[13]) newRow['address1'] = validate.clean(row[7]) newRow['address2'] = validate.clean(row[8]) newRow['town'] = validate.clean(row[9]) newRow['packingSlip'] = 1 newRow['country'] = validate.country(validate.clean( row[12])) or 'US' if not newRow['country']: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( path) + "' was skipped.\n" msg += 'Could not validate country: ' + row[12] errors.append(msg) continue newRow['region'] = validate.region(validate.clean(row[10]), newRow['country']) if not newRow['region']: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( path) + "' was skipped.\n" msg += 'Could not validate region: ' + row[10] errors.append(msg) continue newRow['postCode'] = validate.postCode(validate.clean(row[11]), newRow['country']) if not newRow['postCode']: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( path) + "' was skipped.\n" msg += 'Could not validate post code: ' + row[11] errors.append(msg) continue if len(columns) == len(newRow): parsedRows.append(list(newRow.values())) else: print("Oops, Dealchicken order parser added a column") quit() prevRow = row print("\nImported " + str(len(parsedRows)) + " orders from Dealchicken file '" + os.path.basename(path) + "'") return parsedRows
def getOrders(path, columns): with open(path) as file: reader = csv.reader(file, delimiter='\t') # create a CSV reader object parsedRows = list() # create a list to hold the new rows prevOrderNum = '' next(reader) # skip header row for row in reader: # if more than 2 cols and order number exists and new order if len(row) > 2 and row[0].strip() and row[0] != prevOrderNum: # create a new ordered dictionary to hold the row info newRow = collections.OrderedDict.fromkeys(columns) # map info from input file row to new row dict order_number = validate.clean(row[0]).replace(' ', '') newRow["completeOrderReference"] = order_number newRow["shortOrderReference"] = validate.shortenPossibleAmazon( order_number) newRow["originFile"] = os.path.basename(path) newRow["companyCode"] = 97 newRow["merchantID"] = 10 newRow["fullName"] = validate.clean(row[5]) newRow["phoneNumber"] = "".join( [char for char in row[6] if str.isdigit(char)]) newRow["emailAddress"] = row[4].strip() newRow["address1"] = validate.clean(row[17]) newRow["address2"] = validate.clean(row[18]) newRow["address3"] = validate.clean(row[19]) newRow["town"] = row[20].strip() newRow['country'] = validate.country(validate.clean(row[23])) if not newRow['country']: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( path) + "' was skipped.\n" msg += 'Could not validate country: ' + row[23] + '\n' errors.append(msg) continue newRow["region"] = validate.region(validate.clean(row[21]), newRow['country']) if not newRow["region"]: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( path) + "' was skipped.\n" msg += 'Could not validate state: ' + row[21] + '\n' errors.append(msg) continue newRow['postCode'] = validate.postCode(validate.clean(row[22]), newRow['country']) if not newRow['postCode']: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( path) + "' was skipped.\n" msg += 'Could not validate post code: ' + row[22] + '\n' errors.append(msg) continue newRow["packingSlip"] = 1 if len(columns) == len(newRow): parsedRows.append(list(newRow.values())) else: print("Oops, DSOL Amazon order parser added a column") quit() # save the previous order number prevOrderNum = row[0] print("\nImported " + str(len(parsedRows)) + " orders from Dance Shoes Online file '" + os.path.basename(path) + "'") return parsedRows
def getPackages(path, columns): mensSkus = ["A330101", "A350501"] lines = list() # this list will hold the whole file completedLines = list() with open(path) as file: reader = csv.reader(file, delimiter='\t') next(reader) # skip header row for row in reader: # read the whole file into memory so that I can index it and # iterate over parts of it multiple times if len(row) > 2 and row[10]: # if > 2 cols and sku exists lines.append(row) orderStart = 0 orderEnd = 0 while orderEnd < len(lines): orderEnd += 1 # while the current line has the same order number as the starting line while orderEnd < len( lines) and lines[orderEnd][0] == lines[orderStart][0]: orderEnd += 1 # increment the orderEnd counter # grab the slice of the file that contains the next order currentOrder = lines[orderStart:orderEnd] # create a new ordered dictionary to hold the row info newRow = collections.OrderedDict.fromkeys(columns) # FIGURE OUT WHAT TO DO WITH THIS ORDER order_number = validate.clean(currentOrder[0][0]).replace(' ', '') newRow["shortOrderReference"] = validate.shortenPossibleAmazon( order_number) country = validate.country(validate.clean(currentOrder[0][7])) newRow["merchantID"] = 10 newRow["returnCompany"] = "DanceShoesOnline.com" newRow["returnAdd1"] = "8900 Rosehill Rd" newRow["returnAdd2"] = "Unit B." newRow["returnCity"] = "Lenexa" newRow["returnState"] = "KS" newRow["returnZip"] = "66214-1656" newRow["bulk"] = 0 itemCount = sum(int(row[9]) for row in currentOrder) # orders with 1 item if itemCount == 1: line = currentOrder[0] sku = line[7][:-1].strip() womens = sku not in mensSkus attribString = line[8][line[8].find("("):].replace("(", "").replace( ")", "") attributes = attribString.split(",") size = 0 if attributes[0].strip(): size = float(attributes[0].strip()) if size and size < 9 and womens: newRow["packageNumber"] = 1 newRow["carrier"] = 26 newRow["serviceClass"] = 10 newRow["length"] = 10.25 newRow["width"] = 7 newRow["height"] = 3.5 if size and size < 7: newRow["weight"] = 1 else: newRow["weight"] = 1.2 newRow['note'] = 'Small box' # 1 women's 9 and above or 1 men's else: newRow["packageNumber"] = 1 newRow["carrier"] = 26 newRow["serviceClass"] = 10 newRow["length"] = 12.25 newRow["width"] = 7.25 newRow["height"] = 4.25 newRow["weight"] = 1.2 newRow['note'] = 'Large box' # orders with 2 items elif itemCount == 2: # assume we will be able to ship combo # and then try to prove this false canShipCombo = True for line in currentOrder: sku = line[10][:-1].strip() womens = sku not in mensSkus attribString = line[8][line[8].find("("):].replace("(", "").replace( ")", "") attributes = attribString.split(",") size = 0 if attributes[0].strip(): size = float(attributes[0].strip()) if not size or not womens or not size < 9: canShipCombo = False if canShipCombo: newRow["packageNumber"] = 1 newRow["carrier"] = 26 newRow["serviceClass"] = 10 newRow["length"] = 14 newRow["width"] = 10.25 newRow["height"] = 3.5 newRow["weight"] = 2.2 newRow['note'] = 'Double box' else: # create a generic USPS package newRow['packageNumber'] = 1 newRow['carrier'] = 26 newRow['serviceClass'] = 10 newRow['note'] = 'Dim add' # orders with more than 2 items else: if country == 'PR': # create a generic USPS package newRow['packageNumber'] = 1 newRow['carrier'] = 26 newRow['serviceClass'] = 10 newRow['note'] = 'Dim add' else: orderStart = orderEnd # move on to the next order continue # don't create a package # save the package row in completedLines if len(columns) == len(newRow): completedLines.append(list(newRow.values())) else: print("Oops, DSOL Amazon shipping allocator added a column") quit() orderStart = orderEnd # move on to the next order print("Created " + str(len(completedLines)) + " packages from '" + os.path.basename(path) + "'") return completedLines
def getOrders(self, columns): with open(self.file) as file: prevRow = list() parsedRows = list() reader = csv.reader(file) next(reader) # skip header row for row in reader: if len(row) < 2 or (prevRow and row[0] == prevRow[0]): continue # skip if < 2 cols or same order as prev row # create a new ordered dictionary to hold the row info newRow = collections.OrderedDict.fromkeys(columns) # set company and market self.companyCode = row[2] self.marketId = row[0][:2] self.market = row[0][3:] newRow['marketId'] = self.market # save market id for confirmations newRow['companyCode'] = self.companyCode newRow['merchantID'] = self.getMarketParam('merchantID') if not newRow['merchantID']: continue newRow['completeOrderReference'] = validate.clean(row[1]) newRow['shortOrderReference'] = validate.shortenPossibleAmazon(row[1]) newRow['fullName'] = validate.clean(row[3]) newRow["originFile"] = os.path.basename(self.file) newRow['phoneNumber'] = validate.phone(row[4]) newRow['address1'] = validate.clean(row[5]) newRow['address2'] = validate.clean(row[6]) newRow['town'] = validate.clean(row[7]) newRow['packingSlip'] = 1 newRow['country'] = validate.country(validate.clean(row[10])) if not newRow['country']: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(self.file) + "' was skipped.\n" msg += 'Could not validate country: ' + row[10] self.errors.add(msg) continue newRow['region'] = validate.region(validate.clean(row[8]), newRow['country']) if not newRow['region']: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(self.file) + "' was skipped.\n" msg += 'Could not validate region: ' + row[8] self.errors.add(msg) continue newRow['postCode'] = validate.postCode(validate.clean(row[9]), newRow['country']) if not newRow['postCode']: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(self.file) + "' was skipped.\n" msg += 'Could not validate post code: ' + row[9] self.errors.add(msg) continue if len(columns) == len(newRow): parsedRows.append(list(newRow.values())) else: print("Oops, standard order parser added a column") quit() prevRow = row print("\nImported " + str(len(parsedRows)) + " orders from "+self.market+" file '" + os.path.basename(self.file) + "'") return parsedRows
def getOrders(path, columns): with open(path) as file: prevRow = list() parsedRows = list() reader = csv.reader(file) next(reader) # skip header row for row in reader: if len(row) < 2 or not row[0]: continue # skip if < 2 cols no order number # create a new ordered dictionary to hold the row info newRow = collections.OrderedDict.fromkeys(columns) company = os.path.split(os.path.dirname(path))[1] if company.upper() == 'BETAFRESH': newRow['companyCode'] = 113 elif company.upper() == 'MARVELLOUS': newRow['companyCode'] = 112 else: print('Unknown company:' + company) quit() newRow['merchantID'] = 36 newRow['completeOrderReference'] = validate.clean(row[0]) newRow['shortOrderReference'] = validate.clean(row[0]) newRow["originFile"] = os.path.basename(path) newRow['fullName'] = validate.clean(row[6]) newRow['phoneNumber'] = validate.phone(row[40]) newRow['address1'] = validate.clean(row[7]) newRow['address2'] = validate.clean(row[8]) newRow['town'] = validate.clean(row[9]) newRow['packingSlip'] = 1 newRow['country'] = validate.country(validate.clean(row[12])) if not newRow['country']: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( path) + "' was skipped.\n" msg += 'Could not validate country: ' + row[12] errors.append(msg) continue newRow['region'] = validate.region(validate.clean(row[10]), newRow['country']) if not newRow['region']: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( path) + "' was skipped.\n" msg += 'Could not validate region: ' + row[10] errors.append(msg) continue newRow['postCode'] = validate.postCode(validate.clean(row[11]), newRow['country']) if not newRow['postCode']: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( path) + "' was skipped.\n" msg += 'Could not validate post code: ' + row[11] errors.append(msg) continue if len(columns) == len(newRow): parsedRows.append(list(newRow.values())) else: print("Oops, Groupon order parser added a column") quit() print("\nImported " + str(len(parsedRows)) + " orders from Groupon file '" + os.path.basename(path) + "'") return parsedRows
def getOrders(path, columns): with open(path) as file: reader = csv.reader(file, delimiter='\t') # create a CSV reader object parsedRows = list() # create a list to hold the new rows prevOrderNum = '' next(reader) # skip header row for row in reader: # if more than 2 cols and order number exists and new order if len(row) > 2 and row[0].strip() and row[0] != prevOrderNum: # create a new ordered dictionary to hold the row info newRow = collections.OrderedDict.fromkeys(columns) # map info from input file row to new row dict order_number = validate.clean(row[0]).replace(' ','') newRow["completeOrderReference"] = order_number newRow["shortOrderReference"] = validate.shortenPossibleAmazon(order_number) newRow["originFile"] = os.path.basename(path) newRow["companyCode"] = 97 newRow["merchantID"] = 10 newRow["fullName"] = validate.clean(row[5]) newRow["phoneNumber"] = "".join([char for char in row[6] if str.isdigit(char)]) newRow["emailAddress"] = row[4].strip() newRow["address1"] = validate.clean(row[17]) newRow["address2"] = validate.clean(row[18]) newRow["address3"] = validate.clean(row[19]) newRow["town"] = row[20].strip() newRow['country'] = validate.country(validate.clean(row[23])) if not newRow['country']: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += 'Could not validate country: ' + row[23] + '\n' errors.append(msg) continue newRow["region"] = validate.region(validate.clean(row[21]), newRow['country']) if not newRow["region"]: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += 'Could not validate state: ' + row[21] + '\n' errors.append(msg) continue newRow['postCode'] = validate.postCode(validate.clean(row[22]), newRow['country']) if not newRow['postCode']: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += 'Could not validate post code: ' + row[22] + '\n' errors.append(msg) continue newRow["packingSlip"] = 1 if len(columns) == len(newRow): parsedRows.append(list(newRow.values())) else: print("Oops, DSOL Amazon order parser added a column") quit() # save the previous order number prevOrderNum = row[0] print("\nImported " + str(len(parsedRows)) + " orders from Dance Shoes Online file '" + os.path.basename(path) + "'") return parsedRows
def getPackages(path, columns): mensSkus = ["A330101","A350501"] lines = list() # this list will hold the whole file completedLines = list() with open(path) as file: reader = csv.reader(file, delimiter='\t') next(reader) # skip header row for row in reader: # read the whole file into memory so that I can index it and # iterate over parts of it multiple times if len(row) > 2 and row[10]: # if > 2 cols and sku exists lines.append(row) orderStart = 0 orderEnd = 0 while orderEnd < len(lines): orderEnd += 1 # while the current line has the same order number as the starting line while orderEnd < len(lines) and lines[orderEnd][0] == lines[orderStart][0]: orderEnd += 1 # increment the orderEnd counter # grab the slice of the file that contains the next order currentOrder = lines[orderStart:orderEnd] # create a new ordered dictionary to hold the row info newRow = collections.OrderedDict.fromkeys(columns) # FIGURE OUT WHAT TO DO WITH THIS ORDER order_number = validate.clean(currentOrder[0][0]).replace(' ','') newRow["shortOrderReference"] = validate.shortenPossibleAmazon(order_number) country = validate.country(validate.clean(currentOrder[0][7])) newRow["merchantID"] = 10 newRow["returnCompany"] = "DanceShoesOnline.com" newRow["returnAdd1"] = "8900 Rosehill Rd" newRow["returnAdd2"] = "Unit B." newRow["returnCity"] = "Lenexa" newRow["returnState"] = "KS" newRow["returnZip"] = "66214-1656" newRow["bulk"] = 0 itemCount = sum(int(row[9]) for row in currentOrder) # orders with 1 item if itemCount == 1: line = currentOrder[0] sku = line[7][:-1].strip() womens = sku not in mensSkus attribString = line[8][line[8].find("("):].replace("(","").replace(")","") attributes = attribString.split(",") size = 0 if attributes[0].strip(): size = float(attributes[0].strip()) if size and size < 9 and womens: newRow["packageNumber"] = 1 newRow["carrier"] = 26 newRow["serviceClass"] = 10 newRow["length"] = 10.25 newRow["width"] = 7 newRow["height"] = 3.5 if size and size < 7: newRow["weight"] = 1 else: newRow["weight"] = 1.2 newRow['note'] = 'Small box' # 1 women's 9 and above or 1 men's else: newRow["packageNumber"] = 1 newRow["carrier"] = 26 newRow["serviceClass"] = 10 newRow["length"] = 12.25 newRow["width"] = 7.25 newRow["height"] = 4.25 newRow["weight"] = 1.2 newRow['note'] = 'Large box' # orders with 2 items elif itemCount == 2: # assume we will be able to ship combo # and then try to prove this false canShipCombo = True for line in currentOrder: sku = line[10][:-1].strip() womens = sku not in mensSkus attribString = line[8][line[8].find("("):].replace("(","").replace(")","") attributes = attribString.split(",") size = 0 if attributes[0].strip(): size = float(attributes[0].strip()) if not size or not womens or not size < 9: canShipCombo = False if canShipCombo: newRow["packageNumber"] = 1 newRow["carrier"] = 26 newRow["serviceClass"] = 10 newRow["length"] = 14 newRow["width"] = 10.25 newRow["height"] = 3.5 newRow["weight"] = 2.2 newRow['note'] = 'Double box' else: # create a generic USPS package newRow['packageNumber'] = 1 newRow['carrier'] = 26 newRow['serviceClass'] = 10 newRow['note'] = 'Dim add' # orders with more than 2 items else: if country == 'PR': # create a generic USPS package newRow['packageNumber'] = 1 newRow['carrier'] = 26 newRow['serviceClass'] = 10 newRow['note'] = 'Dim add' else: orderStart = orderEnd # move on to the next order continue # don't create a package # save the package row in completedLines if len(columns) == len(newRow): completedLines.append(list(newRow.values())) else: print("Oops, DSOL Amazon shipping allocator added a column") quit() orderStart = orderEnd # move on to the next order print("Created " + str(len(completedLines)) + " packages from '" + os.path.basename(path) + "'") return completedLines
def getOrders(path, columns): with open(path) as file: prevRow = list() parsedRows = list() reader = csv.reader(file) next(reader) # skip header row for row in reader: if len(row) < 2 or (prevRow and row[0] == prevRow[0]): continue # skip if < 2 cols or same order as prev row # create a new ordered dictionary to hold the row info newRow = collections.OrderedDict.fromkeys(columns) newRow['companyCode'] = 112 # marvellous newRow['merchantID'] = 36 if validate.clean(row[1]).lower() == "ellorefemme.com": newRow['merchantDivisionCode'] = 1 elif validate.clean(row[1]).lower() == "widgetlove.com": newRow['merchantDivisionCode'] = 2 newRow['completeOrderReference'] = validate.clean(row[0]) newRow['shortOrderReference'] = validate.shortenPossibleAmazon(row[0]) newRow['fullName'] = validate.clean(row[3]) + ' ' + validate.clean(row[4]) newRow["originFile"] = os.path.basename(path) newRow['phoneNumber'] = validate.phone(row[10]) newRow['address1'] = validate.clean(row[5]) newRow['town'] = validate.clean(row[6]) newRow['packingSlip'] = 1 newRow['country'] = validate.country(validate.clean(row[9])) if not newRow['country']: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += 'Could not validate country: ' + row[9] errors.append(msg) continue newRow['region'] = validate.region(validate.clean(row[7]), newRow['country']) if not newRow['region']: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += 'Could not validate region: ' + row[7] errors.append(msg) continue newRow['postCode'] = validate.postCode(validate.clean(row[8]), newRow['country']) if not newRow['postCode']: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += 'Could not validate post code: ' + row[8] errors.append(msg) continue if len(columns) == len(newRow): parsedRows.append(list(newRow.values())) else: print("Oops, LTM order parser added a column") quit() prevRow = row print("\nImported " + str(len(parsedRows)) + " orders from Lightake file '" + os.path.basename(path) + "'") return parsedRows
def getOrders(path, columns): with open(path) as file: prevRow = list() parsedRows = list() reader = csv.reader(file) next(reader) # skip header row for row in reader: if len(row) < 2 or not row[0]: continue # skip if < 2 cols no order number # create a new ordered dictionary to hold the row info newRow = collections.OrderedDict.fromkeys(columns) company = os.path.split(os.path.dirname(path))[1] if company.upper() == 'BETAFRESH': newRow['companyCode'] = 113 elif company.upper() == 'MARVELLOUS': newRow['companyCode'] = 112 else: print('Unknown company:' + company) quit() newRow['merchantID'] = 36 newRow['completeOrderReference'] = validate.clean(row[0]) newRow['shortOrderReference'] = validate.clean(row[0]) newRow["originFile"] = os.path.basename(path) newRow['fullName'] = validate.clean(row[6]) newRow['phoneNumber'] = validate.phone(row[40]) newRow['address1'] = validate.clean(row[7]) newRow['address2'] = validate.clean(row[8]) newRow['town'] = validate.clean(row[9]) newRow['packingSlip'] = 1 newRow['country'] = validate.country(validate.clean(row[12])) if not newRow['country']: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += 'Could not validate country: ' + row[12] errors.append(msg) continue newRow['region'] = validate.region(validate.clean(row[10]), newRow['country']) if not newRow['region']: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += 'Could not validate region: ' + row[10] errors.append(msg) continue newRow['postCode'] = validate.postCode(validate.clean(row[11]), newRow['country']) if not newRow['postCode']: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += 'Could not validate post code: ' + row[11] errors.append(msg) continue if len(columns) == len(newRow): parsedRows.append(list(newRow.values())) else: print("Oops, Groupon order parser added a column") quit() print("\nImported " + str(len(parsedRows)) + " orders from Groupon file '" + os.path.basename(path) + "'") return parsedRows
def getOrders(path, columns): with open(path) as file: reader = csv.reader(file) # create a CSV reader object parsedRows = list() # create a list to hold the new rows next(reader) # skip header row for row in reader: # create a new ordered dictionary to hold the row info newRow = collections.OrderedDict.fromkeys(columns) if len(row) < 2 or not row[10].strip(): continue # skip row if < 2 cols or no sku if row[0]: # this line has an order number # map info from input file row to new row dict order_number = validate.clean(row[0]).replace(' ','') if '&' in order_number: newRow["completeOrderReference"] = order_number.replace('&','/') newRow["shortOrderReference"] = validate.shortenPossibleAmazon(order_number.split('&')[0]) else: newRow["completeOrderReference"] = order_number newRow["shortOrderReference"] = validate.shortenPossibleAmazon(order_number) newRow["originFile"] = os.path.basename(path) newRow["companyCode"] = 97 newRow["merchantID"] = 10 newRow["fullName"] = row[1].strip() + " " + row[2].strip() newRow["phoneNumber"] = "".join([char for char in row[8] if str.isdigit(char)]) newRow["emailAddress"] = row[9].strip() newRow["address1"] = row[3].strip() newRow["town"] = row[4].strip() newRow['country'] = validate.country(validate.clean(row[7])) if not newRow['country']: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += 'Could not validate country: ' + row[7] + '\n' errors.append(msg) continue newRow["region"] = validate.region(validate.clean(row[5]), newRow['country']) if not newRow["region"]: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += 'Could not validate state: ' + row[5] + '\n' errors.append(msg) continue newRow['postCode'] = validate.postCode(validate.clean(row[6]), newRow['country']) if not newRow['postCode']: msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(path) + "' was skipped.\n" msg += 'Could not validate post code: ' + row[6] + '\n' errors.append(msg) continue newRow["packingSlip"] = 1 if len(columns) == len(newRow): parsedRows.append(list(newRow.values())) else: print("Oops, DSOL order parser added a column") quit() print("\nImported " + str(len(parsedRows)) + " orders from Dance Shoes Online file '" + os.path.basename(path) + "'") return parsedRows
def getOrders(path, columns): with open(path) as file: reader = csv.reader(file) # create a CSV reader object parsedRows = list() # create a list to hold the new rows next(reader) # skip header row for row in reader: # create a new ordered dictionary to hold the row info newRow = collections.OrderedDict.fromkeys(columns) if len(row) < 2 or not row[10].strip(): continue # skip row if < 2 cols or no sku if row[0]: # this line has an order number # map info from input file row to new row dict order_number = validate.clean(row[0]).replace(' ', '') if '&' in order_number: newRow["completeOrderReference"] = order_number.replace( '&', '/') newRow[ "shortOrderReference"] = validate.shortenPossibleAmazon( order_number.split('&')[0]) else: newRow["completeOrderReference"] = order_number newRow[ "shortOrderReference"] = validate.shortenPossibleAmazon( order_number) newRow["originFile"] = os.path.basename(path) newRow["companyCode"] = 97 newRow["merchantID"] = 10 newRow["fullName"] = row[1].strip() + " " + row[2].strip() newRow["phoneNumber"] = "".join( [char for char in row[8] if str.isdigit(char)]) newRow["emailAddress"] = row[9].strip() newRow["address1"] = row[3].strip() newRow["town"] = row[4].strip() newRow['country'] = validate.country(validate.clean(row[7])) if not newRow['country']: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( path) + "' was skipped.\n" msg += 'Could not validate country: ' + row[7] + '\n' errors.append(msg) continue newRow["region"] = validate.region(validate.clean(row[5]), newRow['country']) if not newRow["region"]: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( path) + "' was skipped.\n" msg += 'Could not validate state: ' + row[5] + '\n' errors.append(msg) continue newRow['postCode'] = validate.postCode(validate.clean(row[6]), newRow['country']) if not newRow['postCode']: msg = newRow[ 'completeOrderReference'] + " from file '" + os.path.basename( path) + "' was skipped.\n" msg += 'Could not validate post code: ' + row[6] + '\n' errors.append(msg) continue newRow["packingSlip"] = 1 if len(columns) == len(newRow): parsedRows.append(list(newRow.values())) else: print("Oops, DSOL order parser added a column") quit() print("\nImported " + str(len(parsedRows)) + " orders from Dance Shoes Online file '" + os.path.basename(path) + "'") return parsedRows