Commits

w31rd0  committed 1149a7b

web portion draft

  • Participants

Comments (0)

Files changed (1)

+import time, sys
+from twisted.web import server, resource
+from twisted.internet import reactor, protocol
+from twisted.python import log
+from twisted.words.protocols import irc
+from twisted.web.client import Response
+
+
+class Simple(resource.Resource):
+    isLeaf = True
+    users = {}
+
+    def render_GET(self, request):
+        return """
+        <html>
+          <ul>%s</ul>
+          <form method="POST">
+            <input type="text" name="username">
+            <input type="text" name="status">
+            <input type="submit">
+          </form>
+        </html>
+        """ % (
+            ''.join('<li>%s: %s</li>' % (k, v) for k, v in self.users.iteritems())
+        )
+
+    def render_POST(self, request):
+        username = None
+        status = None
+        if 'username' in request.args:
+            username = request.args['username'][0]
+        if 'status' in request.args:
+            status = request.args['status'][0]
+        if (username and status):
+            self.users[username] = status
+        request.setResponseCode(302)
+        request.setHeader('Location', '/')
+        return ''
+
+
+if __name__ == '__main__':
+    site = server.Site(Simple())
+    reactor.listenTCP(8080, site)
+    reactor.run()