Example #1
0
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
Example #2
0
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'] = 46

            newRow['completeOrderReference'] = validate.clean(row[0])
            newRow['shortOrderReference'] = validate.clean(row[0].split('_')[-1])
            newRow['fullName'] = validate.clean(row[5]) + ' ' + validate.clean(row[6])
            newRow["originFile"] = os.path.basename(path)
            newRow['address1'] = validate.clean(row[7])
            newRow['town'] = validate.clean(row[6])
            newRow['packingSlip'] = 1
            
            newRow['country'] = 'US'
            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[9]), newRow['country'])
            if not newRow['region']:
                msg = newRow['completeOrderReference'] + " from file '" + os.path.basename(path) + "' was skipped.\n"
                msg += 'Could not validate region: ' + row[9]
                errors.append(msg)
                continue

            newRow['postCode'] = validate.postCode(validate.clean(row[10]), 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[10]
                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
Example #3
0
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
Example #4
0
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
Example #5
0
    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
Example #6
0
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
Example #7
0
    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
Example #8
0
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
Example #9
0
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
Example #10
0
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
Example #11
0
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
Example #12
0
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
Example #13
0
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