Run loop is working.
authorEric S. Raymond <esr@thyrsus.com>
Sat, 25 Aug 2012 11:06:10 +0000 (07:06 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Sat, 25 Aug 2012 11:06:10 +0000 (07:06 -0400)
irker.py

index 7749e949e9b88ab06d671a37fc4cf2180b361c92..3c66e1a8f588e69b3a3cbe8c95d52635c283e141 100755 (executable)
--- a/irker.py
+++ b/irker.py
@@ -6,5 +6,30 @@ Takes JSON objects of the form {'channel':<channel-url>, 'message':<text>}
 and relays to IRC channels.
 
 """
-import os, sys, json, irclib
+import os, sys, json, irclib, getopt
 
+class Irker:
+    "Persistent IRC multiplexer."
+    def __init__(self):
+        self.botpool = {}
+    def logerr(self, errmsg):
+        "Log a processing error."
+        sys.stderr.write(errmsg)
+    def run(self, ifp):
+        "Accept JSON relay requests from specified stream."
+        while True:
+            inp = ifp.readline()
+            if not inp:
+                break
+            try:
+                request = json.loads(inp.strip())
+            except ValueError:
+                self.logerr("irker: can't recognize JSON on input.\n")
+                break
+            self.relay(request)
+    def relay(self, request):
+        print request
+
+if __name__ == '__main__':
+    irker = Irker()
+    irker.run(sys.stdin)