示例#1
0
def generate_cph_vin(num):
    is_valid = False
    recursion_depth = 1
    while True:
        if recursion_depth == 500:
            break
        if is_valid:
            break
        # inp = input('Please enter the last 6 or 8 characters of the VIN:\n')
    
        if len(num) == 6:
            char10 = "3"
            vinYear = getRandomVinStart()
            char = getRandomVinChar()
            v = 'CPH{0}{1}{2}'.format(vinYear.First8[3:], char, char10)
            valid = ValidateVIN(v)
            # CPH120EG03P111111
            while not valid[0]:
                if len(v) == 17:
                    valid = ValidateVIN(v)
                    if valid[0]:
                        is_valid = True
                        break
                    
                if valid[2] == 'Invalid Length':
                    v = 'CPH{0}{1}{2}'.format(vinYear.First8[3:], char, char10)
                    for i in range(1):
                        v += getRandomVinChar()
                    checkChar = getCheckSumChar(v)
                    v = '{0}{1}{2}{3}'.format(v[0:8], checkChar, v[9:], num)
                elif valid[2] == 'Invalid Checksum Character':
                    checkChar = getCheckSumChar(v)
                    v = '{0}{1}{2}'.format(v[0:8], checkChar, v[9:])
                elif valid[2] == 'Unable to Generate':
                    # return (False, valid[1], 'Unable to Generate')
                    # print('Cannot generate a random vin based off the the characters you gave and the VDS selected.')
                    break
        # CPHNL12E639111111
        elif len(num) == 8:
            vinYear = getRandomVinStart()
            char = getRandomVinChar()
            
            v = "CPH{0}{1}{2}".format(vinYear.First8[3:], char, num)
            checkChar = getCheckSumChar(v)
            v = '{0}{1}{2}'.format(v[0:8], checkChar, v[9:])
            valid = ValidateVIN(v)
            break
        else:
            print('Error: Make sure your input is either 6 OR 8 characters long.')
            recursion_depth += 1
    v = valid[1]
    # print('It took {0} time(s) to get a vin.'.format(recursion_depth))
    if valid[0]:
        # print('The vin, {0}, is validated'.format(v))
        return (valid[0], 'The vin, {0}, is validated'.format(v), recursion_depth)
    else:
        # print('The vin, {0}, is not validated'.format(v))
        return (valid[0], 'The vin, {0}, is not validated'.format(v), recursion_depth)
def validate_vin(file_path):

    data_origin = pandas.read_csv(file_path, sep='\t', names=['vin', 'make'])

    # data_clean = open("out/data_clean", "w")
    # data_encoded = open("out/data_encoded", "w")
    # data_exception = open("out/data_exception", "w")

    for row in data_origin:
        
        try:

            # record_data = "{0}\t{1}".format(row[0], row[4])
            # record_encoded_data = "{0}\t{1}\t{2}\t{3}".format(row[0], row[4], sum(row[0][:8].encode('utf-8')), 1)

            vin_result = ValidateVIN(row[0].upper())
            print(row)
            if vin_result[0]:
                print(row[0], row[4], sum(row[0][:8].encode('utf-8')), 1)
                # data_clean.write(record_data + "\n")
                # data_encoded.write(record_encoded_data + "\n")
            else:
                print("oops")
                # data_exception.write(record_encoded_data + "\t" + vin_result[2] + "\n")
        except csv.Error as e:
            print(e)
示例#3
0
    def parseReord(self, wmivds, serial, current_principal):

        # Per ISO 3779 valid prefixs for World Manufacturer Identifier
        # and Vehicle Descriptor Section
        # basis: looking for ocr errors that misrepresent portions of the VIN
        # This is done by creating a dictionary of common mistakes and resolution
        # example: record.replace(mfg["kia"]["WMIVDS"][0...n][0], mfg["kia"]["WMIVDS"][0...n][1])
        ocr_common_error = {"WMIVDS": [["SX", "5X"], ["3KP", "5X"]]}

        value = 0.0
        current_principal = 0.0
        current_principal_total = 0

        record = "{0}{1}".format(wmivds, serial)
        current_principal = current_principal

        value = Decimal(sub(r'[^\d.]', '', current_principal))

        # Remove invalid characters from VIN
        for key in self.blacklist:
            record = record.replace(key[0], key[1])

        current_principal_total += value
        result = ValidateVIN(record.upper())
        
        if result[0]:
            # we have good data
            #print record
            print(record, current_principal, current_principal_total)
            # validFile.write(recordData + "\n")
            # encodedFile.write(encodedData + "\n")
        else:

            for key in ocr_common_error["WMIVDS"]:
                record = record.replace(key[0], key[1])

            result = ValidateVIN(record.upper())

            if result[0]:
                print(record, current_principal, current_principal_total)
                #print record
            else: 
                print(record, " invalid", current_principal)
示例#4
0
def runner():
    inp = ''
    while True:
        inp = input('Please enter the last 6 or 8 characters of the VIN:\n')

        if len(inp) == 6:
            char10 = "3"
            vinYear = getRandomVinStart()
            char = getRandomVinChar()
            v = '{0}{1}{2}'.format(vinYear.First8, char, char10)
            valid = ValidateVIN(v)
            while not valid[0]:
                if len(v) == 17:
                    valid = ValidateVIN(v)

                if valid[2] == 'Invalid Length':
                    vin = '{0}{1}{2}'.format(vinYear.First8, char, char10)
                    for i in range(1):
                        v += getRandomVinChar()
                    checkChar = getCheckSumChar(v)
                    v = '{0}{1}{2}'.format(v[0:8], checkChar, v[9], inp)
                elif valid[2] == 'Invalid Checksum Character':
                    checkChar = getCheckSumChar(v)
                    v = '{0}{1}{2}{3}'.format(v[0:8], checkChar, v[9], inp)
            break
        elif len(inp) == 8:
            vinYear = getRandomVinStart()
            char = getRandomVinChar()

            v = "{0}{1}{2}".format(vinYear.First8, char, inp)
            checkChar = getCheckSumChar(v)
            v = '{0}{1}{2}'.format(v[0:8], checkChar, v[9:])
            valid = ValidateVIN(v)
            break
        else:
            print(
                'Error: Make sure your input is either 6 OR 8 characters long.'
            )

    print(v)
    print(len(v))
    print(valid[0])
示例#5
0
def filter_frame(frame_one, filter=None):

    index_vin = 1
    index_make = 2

    for row in frame_one.itertuples():
        try:
            vin = row[index_vin]
            make = row[index_make]
            wmi = row[index_vin][0:3]

            vin_result = ValidateVIN(vin)
            if vin_result[0]:
                if filter is None:
                    print(vin)
                else:
                    if wmi in filter:
                        print(vin)
        except csv.Error as e:
            print(e)
示例#6
0
def export_vin(filePath):

    data = csv.reader(open(filePath), delimiter='\t')

    #file_out = open("training/output.dat", "w")

    i = 0

    # vins = [r[0].upper() for r in data]
    #results = ValidateVIN(vins, many=True)
    # invalidVins = [r for r in ValidateVIN(vins, many=True) if not r[0]]

    # for v in invalidVins:
    #     print "%s\t%s\t%s" % v

    validFile = open("validVins.txt", "w")
    invalidFile = open("invalidVins.txt", "w")

    for row in data:
        # all records
        # recordData = "{0}\t{1}\t{2}\t{3}\t{4}\t{5}".format(row[0], row[1], row[2], row[3], row[4], row[5])
        # vin make
        recordData = "{0}\t{1}".format(row[0], row[4])
        vinResult = ValidateVIN(row[0].upper())
        if vinResult[0]:
            validFile.write(recordData + "\n")
        else:
            invalidFile.write(recordData + "\t" + vinResult[2] + "\n")

        # print "%s\t%s\t%s" % vinResult

        # print "%s\t%s\n" % (row[0], valid[1])

    validFile.flush()
    validFile.close()
    invalidFile.flush()
    invalidFile.close()
示例#7
0
    def parse(self, file):

        # Per ISO 3779 valid prefixs for World Manufacturer Identifier
        # and Vehicle Descriptor Section
        # basis: looking for ocr errors that misrepresent portions of the VIN
        # This is done by creating a dictionary of common mistakes and resolution
        # example: record.replace(mfg["kia"]["WMIVDS"][0...n][0], mfg["kia"]["WMIVDS"][0...n][1])
        ocr_common_error = {"WMIVDS": [["SX", "5X"], ["3KP", "5X"]]}

        #print("Running Kia Parser: " + file)

        value = 0.0
        current_principal = 0.0
        current_principal_total = 0

        tess_data = csv.reader(
            open(file),
            delimiter=' ',
        )

        #print("Common OCR Errors: ")
        #print(ocr_common_error["WMIVDS"][1])

        for row in tess_data:

            if len(row) > 1:

                if len(row[0]) == 11 and len(row[1]) == 6:

                    record = "{0}{1}".format(row[0], row[1])
                    current_principal = row[2]

                    value = Decimal(sub(r'[^\d.]', '', current_principal))

                    # Remove invalid characters from VIN
                    for key in self.blacklist:
                        record = record.replace(key[0], key[1])

                    current_principal_total += value
                    result = ValidateVIN(record.upper())

                    if result[0]:
                        # we have good data
                        #print record
                        print(record, current_principal,
                              current_principal_total)
                        # validFile.write(recordData + "\n")
                        # encodedFile.write(encodedData + "\n")
                    else:

                        for key in ocr_common_error["WMIVDS"]:
                            record = record.replace(key[0], key[1])

                        result = ValidateVIN(record.upper())

                        if result[0]:
                            print(record, current_principal,
                                  current_principal_total)
                            #print record
                        else:
                            print(record, " invalid", current_principal)