Пример #1
0
    def do_GET(self):
        # import pdb; pdb.set_trace()
        parsed_path = urlparse(self.path)
        parsed_qs = parse_qs(parsed_path.query)

        if parsed_path.path == '/':
            self.send_response(200)
            self.end_headers()
            self.wfile.write(b'''<!DOCTYPE html>
<html>
<head>
    <title> cow </title>
</head>
<body>
    <header>
        <nav>
        Click on the link to procede.
        <ul>
            <li><a href="/cowsay">cowsay</a></li>
        </ul>
        </nav>
    <header>''')

        elif parsed_path.path == '/cowsay':
            mutilated = cow.Mutilated()
            msg = mutilated.milk(
                'This is a cow after running thru a combine. If you want to set your own message here replace cowsay in the address bar with: cow?msg=(your message here)'
            )

            self.send_response(200)
            self.end_headers()
            self.wfile.write(str.encode(msg))

        elif parsed_path.path == '/cow':
            try:
                # import pdb; pdb.set_trace()
                text = parsed_qs['msg'][0]
                mutilated = cow.Mutilated()
                msg = mutilated.milk(text)
            except KeyError:
                self.send_response(400)
                self.end_headers()
                self.wfile.write(b'You did something wrong, please stop')
                return

            self.send_response(200)
            self.end_headers()
            self.wfile.write(str.encode(msg))

        else:
            self.send_response(404)
            self.end_headers()
            self.wfile.write(b'404, This is not the page you are looking for')
Пример #2
0
    (morse_char, char) for (char, morse_char) in encode_morse.items())

cowList = {
    "cow": cow.Cowacter(),
    "hellokitty": cow.HelloKitty(),
    "bunny": cow.Bunny(),
    "cheese": cow.Cheese(),
    "milk": cow.Milk(),
    "bong": cow.BongCow(),
    "eyes": cow.Eyes(),
    "legitvore": cow.HeadInCow(),
    "666": cow.Satanic(),
    "frogs": cow.BudFrogs(),
    "daemon": cow.Daemon(),
    "moofasa": cow.Moofasa(),
    "mutilated": cow.Mutilated(),
    "skeleton": cow.Skeleton(),
    "small": cow.Small(),
    "sodomized": cow.Sodomized(),
    "garfield": cow.Stimpy(),
    "tux": cow.Tux(),
    "vader": cow.Vader()
}


def write_file(filename, contents):
    with open(filename, "w", encoding="utf8") as file:
        for item in contents:
            file.write(str(item))
            file.write("\n")