Exemplo n.º 1
0
 def run(self):
     url_map = [
         ("/w00tw00t.*", not_found),
         ("/survey.css", static_file("files/survey.css", "text/css", False)),
         ("/favicon", static_file("files/favicon.gif", "image/gif")),
         ("/robots.txt", static_file("files/robots.txt", "text/plain")),
         ("/[A-z0-9].*", not_found),
         ("/", self.survey_handler),
     ]
     uServer.run(url_map, self.host, self.port)
    response["response"] = 200
    response["header"] = [ ("Content-type", "text/html; charset=utf-8"), ]
    response["data"] = html


def generate_votecodes(n):
    print "generating %i vote codes in: %s" % (n, VOTE_CODE_PATH)
    generated = set()
    while len(generated) < n:
        generated.add(10000000 + random.randint(0, 89999999))
    dump(list(generated), file(VOTE_CODE_PATH, "wb"))
    print "generated %i vote codes in: %s" % (n, VOTE_CODE_PATH)


if __name__ == "__main__":
    if len(sys.argv) == 3 and sys.argv[1] == "--generate-vote-codes":
        generate_votecodes(int(sys.argv[2]))
        sys.exit(0)
    url_map = [
        ("/w00tw00t.*", not_found),
        ("/umfrage.css", static_file("umfrage.css", "text/css", False)),
        ("/favicon", static_file("files/favicon.gif", "image/gif")),
        ("/robots.txt", static_file("files/robots.txt", "text/plain")),
        ("/neu", run),
        ("/[A-z0-9].*", not_found),
        ("/", run),
    ]
    uServer.run(url_map, "127.0.0.1", 8000)
    #uServer.run(url_map, "88.198.106.203", 8080)