def do_compute(self): # step 1, get information from web source web_message = TextHelper.find_text_between_tag(self.web_source, '"gold"/>\n', '\n') print web_message print TextHelper.find_text_between_tag(self.web_source, '"> <!-- ', '-->') print 'Prompt us to send email to leopold!\n' leopold_email_address = '*****@*****.**' leo_mail = Email(None, leopold_email_address, 'Apology', 'Sorry!') EmailHelper.send_mail(leo_mail) try: leo_response = EmailHelper.get_latest_email(leopold_email_address) if leo_response is not None: print "Response email content: %s" % leo_response.get_payload() except error: print "This may be timeout from out of mainland china!" print "You can check from web to get this email content." print ''' Email content: # Never mind that. # # Have you found my broken zip? # # md5: bbb8b499a0eef99b52c7f13f4e78c24b # # Can you believe what one mistake can lead to?''' # step 2, decode mybroken.zip zip_file = 'mybroken.zip' repair_file = 'repair.zip' local_dir = 'repair' md5 = 'bbb8b499a0eef99b52c7f13f4e78c24b' data = array.array('c', open(zip_file, 'rb').read()) if not T26.fix(data, md5): print "Can not fix %s!" % zip_file FileHelper.save_to_zip_file(data, repair_file) FileHelper.unzip_to_directory(repair_file, local_dir) # step 3, set prompt words ImageHelper.show_from_file(local_dir + "/mybroken.gif") prompt_words = 'speed' + string.split(web_message, ' ')[-1] print "Get words %s from picture!" % prompt_words self.set_prompt(prompt_words) # step 4, clean unused file FileHelper.remove_file(repair_file) FileHelper.remove_folder(local_dir) FileHelper.remove_file('readme.txt') FileHelper.remove_file(zip_file)
def do_compute(self): # step 1, get information from web source print TextHelper.find_text_between_tag(self.web_source, '<title>', '</title>') print "words above indicate us to explore the maze from top to bottom" maze_prompt = TextHelper.find_text_between_tag(self.web_source, '<img src="', '">') maze_img = ImageHelper.create_image_from_web( WebHelper.join_url(self.url, maze_prompt), self.user, self.password) width, height = maze_img.size print "Find entrance in the top" for i in range(width): if maze_img.getpixel((i, 0))[2] == 0: entrance = (i, 0) print "(width=%d, height=0), pixel=(%s)" % ( i, maze_img.getpixel(entrance)) break print "Find export at the bottom" for i in range(width): if maze_img.getpixel((i, height - 1))[2] == 0: export = (i, height - 1) print "(width=%d, height=%d), pixel=(%s)" % ( i, height - 1, maze_img.getpixel(export)) # step 2, get out of the maze queue = T24.go_maze(maze_img, entrance, export) # step 3, get information from path zip_file = 'maze.zip' open('maze.zip', 'wb').write(''.join( [chr(maze_img.getpixel(pos[0])[0]) for pos in queue[1::2]])) FileHelper.unzip_to_directory(zip_file, '.') # step 4, get prompt information from picture maze_jpg = 'maze.jpg' ImageHelper.show_from_file(maze_jpg) prompt_words = 'lake' print "Get %s in the picture" % prompt_words self.set_prompt(prompt_words) # step 5, clean unused files FileHelper.remove_file(maze_jpg) FileHelper.remove_file(zip_file)
def do_compute(self): # step 1, get prompt information from web source gif_prompt = TextHelper.find_text_between_tag(self.web_source, '<!-- or maybe ', ' would be more') gif_url = WebHelper.join_url(self.url, gif_prompt) print "Get gif url: %s" % gif_url ImageHelper.show_image_from_web(gif_url, self.user, self.password) local_image = WebHelper.get_url_page(gif_url) WebHelper.download_with_auth(gif_url, local_image, self.user, self.password) ImageHelper.show_from_file(local_image) # step 2, get Image draw img = Image.open(local_image) prompt_img = Image.new("RGB", (500, 200)) draw = ImageDraw.Draw(prompt_img) cx, cy = 0, 100 for frame in range(img.n_frames): img.seek(frame) left, upper, right, lower = img.getbbox() dx = left - 100 dy = upper - 100 if dx == dy == 0: cx += 50 cy = 100 cx += dx cy += dy draw.point([cx, cy]) prompt_img.show() # shows 'bonus' # step 3, set prompt prompt_words = 'bonus' print "get prompt words from image %s" % prompt_words self.set_prompt(prompt_words) # step 4, clean unused files FileHelper.remove_file(local_image)