From 13f954f4ecace0c4888e194c75a26666fa3fc305 Mon Sep 17 00:00:00 2001 From: jaseg Date: Mon, 29 Jul 2013 19:29:32 +0200 Subject: Added a proper setup.py --- ponysay-qotd | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 ponysay-qotd (limited to 'ponysay-qotd') diff --git a/ponysay-qotd b/ponysay-qotd new file mode 100755 index 0000000..2530d8f --- /dev/null +++ b/ponysay-qotd @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +import random +from socketserver import ThreadingMixIn, TCPServer, BaseRequestHandler +import ponysay + +# Quote-Of-The-Day protocol implementation using ponysay backend +# See RFC865 ( https://tools.ietf.org/html/rfc865 ) for details. +# To prevent traffic amplification attacks we are only providing a TCP service. + +class ThreadingTCPServer(ThreadingMixIn, TCPServer): pass + +ponylist = ponysay.list_ponies_with_quotes() + +class QOTDHandler(BaseRequestHandler): + def handle(self): + pony = random.choice(ponylist) + s = ponysay.render_pony(pony, ponysay.random_quote(pony), + balloonstyle=ponysay.balloonstyles['cowsay'], + center=True, + centertext=False) + self.request.sendall(bytes(s, "UTF-8")) + +if __name__ == "__main__": + HOST, PORT = "", 8017 + server = ThreadingTCPServer((HOST, PORT), QOTDHandler) + server.serve_forever() -- cgit