def find_confirmation_code(code): confirmation_code = '' letter_num = 0 colcut = [] # Scan the columns first = True for x in xrange(code.size[0] - 1): # Get the current column and the next one col1 = [xlate_col(code.getpixel((x, y))) for y in xrange(code.size[1])] col2 = [ xlate_col(code.getpixel((x + 1, y))) for y in xrange(code.size[1]) ] # Skip a white column if 1 not in col1: continue # If this is our first column with a letter, add it to the column cut list if first: first = False colcut.append(x - 1) # Check if the next column connects to the current one conn = False for y in xrange(1, code.size[1] - 1): if col1[y] and (col2[y - 1] or col2[y] or col2[y + 1]): conn = True # If the columns are not connected, then we've reached a new letter if conn == False: # If we haven't reached the minimum width, ignore the disconnection # between the two parts of the letter and continue if x - colcut[-1] < MIN_WIDTH: continue #print "Checking letter %d at location %d" % (letter_num, x) colcut.append(x + 1) # Create the letter map letter_array = [] for lx in xrange(colcut[-2], colcut[-1]): for ly in xrange(LETTER_SIZE[1]): pixel = 1 - xlate_col(code.getpixel((lx, ly))) letter_array.append(str(pixel)) letter_map = "".join(letter_array) # Find the best matching letter for our current letter map confirmation_code += match_letter.find_best_letter(letter_map)[0] letter_num += 1 return confirmation_code
def find_confirmation_code(code): confirmation_code = '' letter_num = 0 colcut = [] # Scan the columns first = True for x in xrange(code.size[0]-1): # Get the current column and the next one col1 = [xlate_col(code.getpixel((x,y))) for y in xrange(code.size[1])] col2 = [xlate_col(code.getpixel((x+1,y))) for y in xrange(code.size[1])] # Skip a white column if 1 not in col1: continue # If this is our first column with a letter, add it to the column cut list if first: first = False colcut.append(x-1) # Check if the next column connects to the current one conn = False for y in xrange(1,code.size[1]-1): if col1[y] and (col2[y-1] or col2[y] or col2[y+1]): conn = True # If the columns are not connected, then we've reached a new letter if conn == False: # If we haven't reached the minimum width, ignore the disconnection # between the two parts of the letter and continue if x - colcut[-1] < MIN_WIDTH: continue #print "Checking letter %d at location %d" % (letter_num, x) colcut.append(x+1) # Create the letter map letter_array = [] for lx in xrange(colcut[-2], colcut[-1]): for ly in xrange(LETTER_SIZE[1]): pixel = 1 - xlate_col(code.getpixel((lx,ly))) letter_array.append(str(pixel)) letter_map = "".join(letter_array) # Find the best matching letter for our current letter map confirmation_code += match_letter.find_best_letter(letter_map)[0] letter_num += 1 return confirmation_code
#print "Checking letter %d at location %d" % (letter_num, x) colcut.append(x+1) # Create the letter map letter_array = [] for lx in xrange(colcut[-2], colcut[-1]): for ly in xrange(LETTER_SIZE[1]): pixel = 1 - xlate_col(code.getpixel((lx,ly))) letter_array.append(str(pixel)) letter_map = "".join(letter_array) # Find the best matching letter for our current letter map confirmation_code += match_letter.find_best_letter(letter_map)[0] letter_num += 1 print "Confirmation code: %s" % confirmation_code # Make sure we got 8 letters total if letter_num != 8: print "Wrong number of letters detected!" print "Number of letters: %d" % letter_num sys.exit(1) # Create the query string query_string = "confirmation_code_enter=%s&signup=%s&btnsignup=Sign+Up!" % (confirmation_code, signup) # Resend the signup page with a POST of the confirmation code next_html = opener.open(SIGNUP_LINK, query_string).read()