def do_compute(self): # step 1, get prompt information from web source words_hint = TextHelper.find_text_between_tag(self.web_source, "<!-- ", " -->") print words_hint img_url_short = TextHelper.find_text_between_tag(self.web_source, "<img src=\"", "\" border=") ImageHelper.show_image_from_web(WebHelper.join_url(self.url, img_url_short)) # It shows a same picture with different brightness print "brightness" prompt_url = WebHelper.join_url(self.url, "brightness") print "get new prompt url: %s" % prompt_url # step 2, download gz file from web prompt_url = WebHelper.get_prompt_url_from_web(prompt_url, "<!-- maybe consider ", " -->") local_gz = WebHelper.get_url_page(prompt_url) WebHelper.download_with_auth(prompt_url, local_gz) # step 3, get png data and show the image gz_content = FileHelper.read_gzip_file(local_gz) png = T18.get_png_data_from_diff_data(gz_content) for i in range(3): ImageHelper.show_image_from_data(png[i]) # from image, we can see "../hex/bin.html", "butter", "fly" ==> These last two words will be used in next level prompt_url = "../hex/bin.html" print 'we can see "../hex/bin.html", "butter", "fly" in these image, set new user, password for next level' self.result.set_user_password("butter", "fly") # step 4, set prompt self.set_prompt(prompt_url) # step 5, clean zip file FileHelper.remove_file(local_gz)
def do_compute(self): # step 1. get prompt information from web source words_prompt = TextHelper.find_text_between_tag( self.web_source, "<!-- ", "-->") print words_prompt # remember: 100*100 = (100+99+99+98) + (... url_prompt = TextHelper.find_text_between_tag( self.web_source, "<img src=\"", "\" width=\"100\" height=\"100\">") img_url = WebHelper.join_url(self.url, url_prompt) print "get image url: " + img_url url_ignore, img_data = WebHelper.get_auth_url_content(img_url) # step 2. try to get information from img wire_img = Image.open(StringIO(img_data)) (width, height) = wire_img.size print width, height # The picture size is '10000, 1' ===> 10000 = 100 * 100 # step 3. draw picture in square T14.draw_circle(wire_img) # We can see the picture is cat # step 4. cat url cat_url = WebHelper.join_url(self.url, "cat") url_ignore, cat_content = WebHelper.get_auth_url_content(cat_url) cat_prompt = TextHelper.find_text_between_tag( cat_content, "and its name is <b>", "</b>. you'll hear from him ") # step 5. set prompt for the next level self.set_prompt(cat_prompt)
def do_compute(self): # step 1, get information from web source bell_url = TextHelper.find_text_between_tag(self.web_source, '<a href="', '">') bell_url = WebHelper.join_url(self.url, bell_url) print "Find some url: %s" % bell_url zigzag_jpg = TextHelper.find_text_between_tag(self.web_source, '<img src="', '"> <!--') zigzag_jpg = WebHelper.join_url(self.url, zigzag_jpg) print "Find a picture: %s" % zigzag_jpg gif_prompt = TextHelper.find_text_between_tag(self.web_source, 'did you say ', '? -->') gif_url = WebHelper.change_suffix_url(zigzag_jpg, gif_prompt) print "Get a gif picture: %s" % gif_url # step 2, deal with gif img = ImageHelper.create_image_from_web(gif_url, self.user, self.password) img_content = img.tobytes() img_plt = img.palette.getdata()[1][::3] trans = string.maketrans("".join([chr(i) for i in range(256)]), img_plt) img_tran = img_content.translate(trans) diff = ["", ""] img = Image.new("1", img.size, 0) for i in range(1, len(img_content)): if img_content[i] != img_tran[i - 1]: diff[0] += img_content[i] diff[1] += img_tran[i - 1] img.putpixel(((i - 1) % img.size[0], (i - 1) / img.size[0]), 1) img.show( ) # two words shows in picture: 'not', 'word', between is an key text = bz2.decompress(diff[0]) auth = set() for i in text.split(): if not keyword.iskeyword(i): auth.add(i) # print repeat, switch, ../ring/bell auth = list(auth) print auth for item in auth: if 'html' in item: next_level_url = WebHelper.join_url(self.url, item) auth.remove(item) try: content_ignore = WebHelper.get_auth_web_source( next_level_url, auth[0], auth[1]) self.result.set_user_password(auth[0], auth[1]) print "Set next level user, password = (%s, %s)" % (auth[0], auth[1]) except HTTPError: self.result.set_user_password(auth[1], auth[0]) print "Set next level user, password = (%s, %s)" % (auth[1], auth[0]) # step 3, set next level url self.set_next_level_url(next_level_url)
def do_compute(self): # step 1, get picture from web source prompt_url = TextHelper.find_text_between_tag(self.web_source, "<img src=\"", "\" border=\"0\"/>") cookie_img_url = WebHelper.join_url(self.url, prompt_url) ImageHelper.show_image_from_web(cookie_img_url) # Do you feel familiar with the embed picture? Yes, the level 4 level_4_start_url, ignore_content = WebHelper.get_final_url_content("http://www.pythonchallenge.com/pc/def/linkedlist.html") print "python challenge level 4 start url: " + level_4_start_url # step 2, get traverse start url cookies, level_4_web_source = WebHelper.get_cookie_content_from_url(level_4_start_url) cookie_prompt = ''.join(cookies) # you+should+have+followed+busynothing... print "prompt from start web cookie: " + cookie_prompt new_para = TextHelper.find_text_between_tag(cookie_prompt, "have followed ", "...") print "get new para from cookie prompt: " + new_para origin_start_url = TextHelper.find_text_between_tag(level_4_web_source, "<center>\n<a href=\"", "\">") print "get origin start url: " + origin_start_url start_url = WebHelper.join_url(level_4_start_url, origin_start_url.replace("nothing", new_para)) print "replace with new para, get final start url: " + start_url # step 3, get traverse start url cookies_collect = WebHelper.get_traverse_cookie(start_url, "and the next busynothing is ") compressed_message = ''.join(cookies_collect) print "Get compressed message from cookies: " + compressed_message # step 4, uncompress message message = bz2.decompress(compressed_message) print "decompressed messsage: %s" % message # decompressed messsage: is it the 26th already? call his father and inform him that "the flowers are \ # on their way". he'll understand. his_father = "Leopold" message = TextHelper.find_text_between_tag(message, "call his father and inform him that \"", "\". he'll ") # step 5, call his father his_father = "Leopold" phone_book_url = "http://www.pythonchallenge.com/pc/phonebook.php" phone = xmlrpclib.ServerProxy(phone_book_url) number = phone.phone(his_father) print "%s number is %s" % (his_father, number) # Leopold number is 555-VIOLIN ignore_url, violin_content = WebHelper.get_auth_url_content(WebHelper.join_url(self.url, "violin")) print violin_content violin_url = TextHelper.find_pattern_in_content(violin_content, "no! i mean yes! but (.*php)")[0] print "violin url is %s" % violin_url leopold_url = WebHelper.join_url(self.url, violin_url) # step 6, send the message opener = urllib2.build_opener() message = "the flowers are on their way" opener.addheaders.append(('Cookie', 'info=' + quote_plus(message))) response = opener.open(leopold_url) leopold_prompt = response.read() # step 7, set next level prompt final_prompt = TextHelper.find_text_between_tag(leopold_prompt, "t you dare to forget the ", ".</font>") self.set_prompt(final_prompt)
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 prompt information from web source print TextHelper.find_text_between_tag(self.web_source, '<!-- ', '-->') wav_suffix = 'wav' print "Above prompt words ask us to replace the suffix of jpg to %s" % wav_suffix wave_img_url = WebHelper.join_url( self.url, TextHelper.find_text_between_tag(self.web_source, '<img src="', '">')) print "wave image web url is %s" % wave_img_url ImageHelper.show_image_from_web( WebHelper.join_url(self.url, wave_img_url), self.user, self.password) print "This picture prompt us: there is 25 block, we need to combine them" # step 2, download waves wave_url = WebHelper.change_suffix_url(wave_img_url, wav_suffix) print "After change suffix: %s" % wave_url local_directory = 't25' FileHelper.mkdir(local_directory) waves = [] for i in range(25): store_path = FileHelper.join_path(local_directory, WebHelper.get_url_page(wave_url)) WebHelper.download_with_auth(wave_url, store_path, self.user, self.password) waves.append(wave.open(store_path)) wave_url = WebHelper.url_add(wave_url) # step 3, Create combine image from waves img = Image.new('RGB', (300, 300), 'black') frames = waves[0].getnframes() print "Totally waves: %d" % len(waves) for i in range(len(waves)): tmp_img = Image.frombytes('RGB', (60, 60), waves[i].readframes(frames)) current_pos = (60 * (i % 5), 60 * (i // 5)) print "Put image to position%s" % str(current_pos) img.paste(tmp_img, current_pos) img.show() # It shows a words 'decent' # step 4, set prompt words prompt_word = 'decent' print "Get prompt words from combined picture: %s" % prompt_word self.set_prompt(prompt_word) # step 5, clean unused file FileHelper.remove_folder(local_directory)
def do_compute(self): # step 1, get prompt form web source email_string = TextHelper.find_text_between_tag(self.web_source, "<!--\n", "\n-->") message = email.message_from_string(email_string) audio = message.get_payload(0).get_payload(decode=True) local_wav = "mainland.wav" WaveHelper.save_base64_file(audio, local_wav) WaveHelper.play(local_wav) # pronounce 'sorry' pronounce_word = "sorry" print "pronounce word: %s" % pronounce_word # step 2, wrong try sorry_url = WebHelper.join_url(self.url, pronounce_word) url_ignore, sorry_content = WebHelper.get_auth_url_content(sorry_url, self.user, self.password) print sorry_content # step 3, reverse the wav data reverse_wave = "sea.wav" WaveHelper.reverse_wave(local_wav, reverse_wave) WaveHelper.play(reverse_wave) # pronounce "you are idiot, a.a.a.a..." print "pronounce word: %s" % "you are idiot, a.a.a.a..." prompt_url = WebHelper.join_url(self.url, "idiot") print "prompt url: %s" % prompt_url # step 4, get next level url next_url = WebHelper.get_prompt_url_from_web(prompt_url, '<br><a href="', '">Continue to the', self.user, self.password) self.set_next_level_url(next_url) # step 5, clean resources FileHelper.remove_file(local_wav) FileHelper.remove_file(reverse_wave)
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 information from url login_url_prompt = TextHelper.find_text_between_tag( self.web_source, "href=\"", "\" />") login_url = WebHelper.join_url(self.url, login_url_prompt) user_encode = TextHelper.find_text_between_tag(self.web_source, "un: '", "'") user = bz2.decompress(user_encode.decode('string_escape')) print "user = "******"pw: '", "'") password = bz2.decompress(password_encode.decode('string_escape')) print "password = " + password # file self.result.set_user_password(user, password) # step 2. Login with user, password self.set_next_level_url(login_url)
def do_compute(self): # step 1, get information from web module_prompt = TextHelper.find_text_between_tag(self.web_source, "<!-- it can't find it. ", '-->') print "First prompt to use module: %s" % module_prompt words_prompt = TextHelper.find_text_between_tag(self.web_source, "<!--\n'", "?'\n-->") print "Second prompt: %s" % words_prompt # step 2, translate prompt words with prompt module table = string.maketrans(''.join(this.d.keys()), ''.join(this.d.values())) message = string.translate(words_prompt, table) print "Message after translate: %s" % message pattern = string.replace(message, 'what', '(\w+)') text = string.translate(this.s, table) # step 3, get prompt prompt_word = re.search(pattern, text, re.I).group(1) print prompt_word self.set_prompt(prompt_word)
def do_compute(self): # step 1. Get text from web source text = TextHelper.find_text_between_tag(self.web_source) # step 2. Get target characters characters = TextHelper.find_pattern_in_content( self.web_source, '[^A-Z][A-Z]{3}(?P<Boss>[a-z])[A-Z]{3}[^A-Z]') # step 3. Get prompt of next level challenge url self.set_prompt(''.join(characters))
def do_compute(self): # step 1, get information from web source data = ''.join( map(chr, [len(i) for i in self.web_source.splitlines()[12:]])) message = bz2.decompress(data) print "Get message from blank: %s" % message # step 2, set prompt information prompt = TextHelper.find_text_between_tag(message, 'I am ', '!') self.set_prompt(prompt)
def read_traverse(txt_name): txt_file = "channel/" + txt_name + ".txt" readme_txt = open(txt_file, 'r').read() print readme_txt if "Next nothing is " in readme_txt: next_name = TextHelper.find_text_between_tag( readme_txt, "Next nothing is ", "") print "Get next file name: " + next_name return T6.read_traverse(next_name) else: return readme_txt
def do_compute(self): # step 1. get information from web first = TextHelper.find_text_between_tag(self.web_source, "first:\n", "second:").strip() first = [int(x) for x in first.split(',')] second = TextHelper.find_text_between_tag(self.web_source, "second:", "-->").strip() second = [int(x) for x in second.split(',')] # step 2. draw prompt img = Image.new('RGB', (500, 500)) draw = ImageDraw.Draw(img) for i in range(0, len(first), 2): draw.line(first[i:i + 4], fill='white') for i in range(0, len(second), 2): draw.line(second[i:i + 4], fill='white') img.show("prompt") # it shows a bull # step 3. set the prompt self.set_prompt("bull")
def do_compute(self): # step 1. get hint from web source prompt_url = TextHelper.find_text_between_tag( self.web_source, "coords=\"326,177,45\" href=\"", "\" />") phone_book_url = WebHelper.join_url(self.url, prompt_url) # step 2. use xmlrpclib server = xmlrpclib.Server(phone_book_url) print server.phone('Bert') # print 555-ITALY # step 3. set prompt self.set_prompt('italy')
def do_compute(self): # step 1, get question from web source words_prompt = TextHelper.find_text_between_tag( self.web_source, "<title>", "</title>") print words_prompt # ask us who is this person? # step 2, get image from web prompt_url = TextHelper.find_text_between_tag(self.web_source, "<img src=\"", "\"><br>") img_url = WebHelper.join_url(self.url, prompt_url) url_ignore, img_data = WebHelper.get_auth_url_content(img_url) ImageHelper.show_image_from_web( img_url) # a calendar shows a date January, 26, 1XX6 month = 1 day = 26 # step 3, calculate possible date possible_year = filter(lambda y: isleap(y) and 0 == weekday(y, 1, 26), range(1006, 2000, 10)) print possible_year # step 4, get the date with more prompt information words_prompt = TextHelper.find_text_between_tag( self.web_source, "<!-- todo: ", " -->") print words_prompt # prompt us the date after January, 26 is some day special for memory day += 1 words_prompt = TextHelper.find_text_between_tag( self.web_source, "<center>\n<!-- ", " -->") print words_prompt # prompt us choose the second youngest year = possible_year[-2] print "The day special for flower is " + str(year) + "/" + str( month) + "/" + str(day) # some body may know but I don't know this day is the birthday of mozart # https://en.wikipedia.org/wiki/January_27#Births # step 5, set prompt for the next leve self.set_prompt("mozart")
def do_compute(self): # step 1. Get hint from page source hint = TextHelper.find_text_between_tag(self.web_source, "<html> <!-- <-- ", " -->\n<head>") zip_url = WebHelper.change_suffix_url(self.url, hint) # step 2. Download zip to local and extract tmp_zip = zip_url[zip_url.rindex("/") + 1:] tmp_folder = tmp_zip[:tmp_zip.index(".")] WebHelper.download(zip_url, tmp_zip) zip_ref = zipfile.ZipFile(tmp_zip, 'r') zip_ref.extractall(tmp_folder) zip_ref.close() # step 3. Get next hint readme_txt = open(tmp_folder + "/readme.txt", 'r').read() start_txt = TextHelper.find_text_between_tag(readme_txt, "hint1: start from ", "\n") next_hint = T6.read_traverse(start_txt) print next_hint # Hint: Collect the comments. # step 4. Get comments print T6.collect_comments( tmp_zip, start_txt) # Comments: HOCKEY (Small letter oxygen) # step 5. Wrong way wrong_url = WebHelper.join_url(self.url, "hockey") print WebHelper.get_web_source( wrong_url) # it's in the air. look at the letters. # step 6. Get next url hint self.set_prompt(WebHelper.join_url(self.url, "oxygen")) # step 7. Clean folder FileHelper.remove_folder(tmp_folder) FileHelper.remove_file(tmp_zip)
def collect_comments(zip_path, txt_name): zip_ref = zipfile.ZipFile(zip_path, 'r') collect = '' while True: txt_file = "channel/" + txt_name + ".txt" readme_txt = open(txt_file, 'r').read() if "Next nothing is " in readme_txt: collect += zip_ref.getinfo(txt_name + ".txt").comment txt_name = TextHelper.find_text_between_tag( readme_txt, "Next nothing is ", "") else: break zip_ref.close() return collect
def do_compute(self): # step 1. get information from web source print TextHelper.find_text_between_tag(self.web_source, '<!--\n', '\n-->') beer_url = TextHelper.find_text_between_tag(self.web_source, '<img src="', '" border="0"') beer_url = WebHelper.join_url(self.url, beer_url) print beer_url beer_url = WebHelper.url_add(beer_url) beer_url = WebHelper.change_suffix_url(beer_url, 'png') # step 2. try out this picture beer_img = ImageHelper.create_image_from_web(beer_url, self.user, self.password) data = list(beer_img.getdata()) local_dir = 'img_data' FileHelper.mkdir(local_dir) print len(data) count = 0 while len(data) > 0: if self.is_int_sqrt(len(data)) and len(data) > 0: count += 1 size = int(math.sqrt(len(data))) print "data length = %i, sqrt value = %i" % (len(data), size) new_img = Image.new('RGB', (size, size)) new_img.putdata(data) new_img.save(os.path.join(local_dir, 'img_%i.png' % count)) max_value = max(data) data = [x for x in data if x != max_value] # step 3, Get hint from these pictures print "check png under %s, you will find many characters!" % local_dir prompt = 'gremlins' print "but only characters %s are in square" % str(list(prompt)) self.set_prompt(prompt) FileHelper.remove_folder(local_dir)
def do_compute(self): # step 1. get prompt from web source hint: len(a[30]) = ? prompt_url = TextHelper.find_text_between_tag(self.web_source, "href=\"", "\" />") sequence = WebHelper.get_auth_web_source( WebHelper.join_url(self.url, prompt_url)) print sequence # a = [1, 11, 21, 1211, 111221, # step 2. compute len(a[30]) a_str = '1' for i in range(30): a_str = T10.read_string(a_str) # step 3. set prompt self.set_prompt(str(len(a_str)))
def do_compute(self): # Step 1. Get string from source code encode_text = TextHelper.find_text_between_tag(self.web_source, "f000f0\">\n", "\n</tr") # Step 2. Translate encode_text from_str = string.lowercase to_str = from_str[2:] + from_str[:2] table = string.maketrans(from_str, to_str) print string.translate(encode_text, table) # Get promote to translate the url with the same table # Step 3. Translate url # Current url is http://www.pythonchallenge.com/pc/def/map.html self.set_prompt(string.translate("map", table))
def do_compute(self): # step 1. Get banner dump data banner_prompt = TextHelper.find_text_between_tag( self.web_source, "peakhell src=\"", "\"/>") banner_url = WebHelper.join_url(self.url, banner_prompt) banner_data = WebHelper.get_web_source(banner_url) # step 2. show the banner banner = '' for line in pickle.loads(banner_data): for char, count in line: banner += char * count banner += '\n' print banner # Get word channel # step 3. Set prompt self.set_prompt("channel")
def do_compute(self): # step 1, get information from web source png_url = TextHelper.find_text_between_tag(self.web_source, '<img src="', '" border="') png_url = WebHelper.join_url(self.url, png_url) print "Get png from web url: %s" % png_url bell_png = ImageHelper.create_image_from_web(png_url, self.user, self.password) green = bell_png.split()[1] message = "" for a, b in T28.paired(green.getdata()): diff = abs(a - b) if diff != 42: message += chr(diff) print 'Prompt Message: %s' % message # whodunnit().split()[0] ? # step 2, set prompt prompt = self.whodunnit().split()[0] self.set_prompt(prompt.lower())
def do_compute(self): # step 1. Get traverse start url start_url_prompt = TextHelper.find_text_between_tag( self.web_source, "<center>\n<a href=\"", "\">") start_url = WebHelper.join_url(self.url, start_url_prompt) print "Get start traverse url" + start_url # start url is http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345 # step 2. Traverse in url, util the end url end_url, end_content = WebHelper.get_traverse_url_content( start_url, "and the next nothing is ") # end url is http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=66831 # step 3. Get the next level url final_url, final_content = WebHelper.get_final_url_content( end_url, end_content) self.set_next_level_url(final_url)
def do_compute(self): # step 1. get prompt information prompt_img_url = TextHelper.find_text_between_tag(self.web_source, "<img src=\"", "\"><br>") img_url = T12.evil_add_url(WebHelper.join_url(self.url, prompt_img_url)) print "get new image url: " + img_url url_ignore, img_data = WebHelper.get_auth_url_content(img_url) img = Image.open(StringIO(img_data)) img.show() # shows: we should use suffix .gfx not .jpg # step 2. get gfx file gfx_url = WebHelper.change_suffix_url(img_url, ".gfx") url_ignore, gfx_data = WebHelper.get_auth_url_content(gfx_url) # step 3. play data cards T12.play_cards(gfx_data) # There were five picture shows : 'dis', 'pro', 'port', 'ional', 'ity' (strikeout) # step 3. set prompt for next level self.set_prompt('disproportional')
def do_compute(self): # step 1. Get text from web source text = TextHelper.find_text_between_tag(self.web_source) # step 2. Calculate the rare characters text_dict = {} for char in text: if char in text_dict.keys(): text_dict[char] += 1 else: text_dict[char] = 1 rare_characters = ''.join( [char for char, count in text_dict.items() if count < 10]) # step 3. Get next url ans = ''.join([char for char in text if char in rare_characters]) self.set_prompt(ans) # Get word 'equality'
def do_compute(self): # step 1. get png url and download png_prompt = TextHelper.find_text_between_tag(self.web_source, "<img src=\"", "\"/>") png_url = WebHelper.join_url(self.url, png_prompt) png_local = WebHelper.get_url_page(png_url) WebHelper.download(png_url, png_local) # step 2. get prompt information png = Image.open(png_local) row = [png.getpixel((x, png.size[1]/2)) for x in range(0, png.size[0], 7)] print ''.join([chr(r) for r, g, b, d in row if r == g and g == b]) # get hint: smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121] # step 3. set prompt for next url self.set_prompt(''.join([chr(i) for i in [105, 110, 116, 101, 103, 114, 105, 116, 121]])) # step . clean file FileHelper.remove_file(png_local)
def do_compute(self): # step 1, get information from web source print TextHelper.find_text_between_tag(self.web_source, ' <!-- ', '-->') print TextHelper.find_text_between_tag(self.web_source, '<font color="gold">\n', '\n </font>') warm_up_url = TextHelper.find_text_between_tag(self.web_source, 'blanks <!-- for ', ' -->') warm_up_url = WebHelper.join_url(self.url, warm_up_url) # step 2, solve first etch-a-scetch file_content = WebHelper.get_auth_url_content(warm_up_url, self.user, self.password)[1] # print "Words in warmup.txt:\n%s" % file_content # sketch = Sketch(file_content) # sketch.play_game() Sketch.play_game(file_content) prompt = 'up' print "It shows an %s tag" % prompt second_file = WebHelper.join_url(warm_up_url, prompt) # step 3, solve the second etch-a-scetch file_content = WebHelper.get_auth_url_content(second_file, self.user, self.password)[1] # sketch = Sketch(file_content) # sketch.play_game() Sketch.play_game(file_content) python = 'python' print "It shows a picture of %s" % python # step 4, search the wiki get prompt information python_url = WebHelper.join_url(self.url, python) print "Python url: %s" % python_url file_content = WebHelper.get_auth_web_source(python_url, self.user, self.password) print TextHelper.find_text_between_tag(file_content, '<font color="gold">', '</font>') prompt = 'beer' print "Search on the wiki %s is the words next to Free" % prompt # step 5, set prompt for next url self.set_prompt(prompt)
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)
def do_compute(self): # step 1, get image link from web source img_prompt = TextHelper.find_text_between_tag(self.web_source, "<img src=\"", "\"><br>") img_url = WebHelper.join_url(self.url, img_prompt) url_ignore, img_data = WebHelper.get_auth_url_content(img_url) img = Image.open(StringIO(img_data)) img.show() width, height = img.size print width, height # step 2, strength the line new_img = Image.new('RGB', (width, height), 'black') for h in range(height): line = [img.getpixel((w, h)) for w in range(width)] pink = line.index(195) line = line[pink:] + line[:pink] for w, pixel in enumerate(line): new_img.putpixel((w, h), pixel) new_img.show() # picture with words: romance # step 3, set prompt self.set_prompt("romance")