import cherrypy
import random

class RandomExcuseGenerator(object):
    def __init__(self, filename):
        file = open(filename)
        self.excuses = [line.strip() for line in file]
        file.close()

    def get(self):
        return random.choice(self.excuses)

class ExcusesApp(object):
    excuses = RandomExcuseGenerator('excuses')

    @cherrypy.expose
    def index(self):
        return """\
<html>
<head>
    <title>Your Next Excuse!</title>
    <style>
    h1 {
        font-family: Arial, Helvetica, Sans-serif;
        background-color:gray;
        margin:0px auto;
        margin-top:200px;
        width:800px;
        text-align:center;
    }

    div.container {
        margin:0px auto;
        width:100%%;
    }
    </style>
</head>
<body>
<div class="container">
<h1>%s</h1>
</div>
</body>""" % self.excuses.get()

if __name__ == '__main__':
    cherrypy.config.update({'server.environment':'production', 
                            'server.socket_port':8082})
    cherrypy.tree.mount(ExcusesApp(), '/excuses')
    cherrypy.server.start()

