예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    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")