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 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, ' <!-- ', '-->') 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 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 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 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")
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")