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 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 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)
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) @staticmethod def is_int_sqrt(number): return int(math.sqrt(number))**2 == number if __name__ == '__main__': current_url = 'http://www.pythonchallenge.com/pc/rock/beer.html' print "start with url: " + current_url challenge = T33(current_url, True, "kohsamui", "thailand") final_url = challenge.get_next_level_url() print "Next Challenge URL: " + final_url # Next Challenge URL: http://www.pythonchallenge.com/pc/rock/arecibo.html web_source = WebHelper.get_auth_web_source(final_url, "kohsamui", "thailand") print TextHelper.find_text_between_tag(web_source, '<title>', '</title>') print TextHelper.find_text_between_tag(web_source, '</font>\n\n', '<br><br>')