From: Laurent Bachelier Date: Wed, 10 Oct 2012 19:02:05 +0000 (+0200) Subject: Support piping text to irk X-Git-Tag: 1.11~3 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=53fbe3f84076959e983a03fe424bbb054b52c8cb;p=irker.git Support piping text to irk Usage: outcmd|irk target - Sending "-" is still possible by echo -|irk target - Signed-off-by: Eric S. Raymond --- diff --git a/irk b/irk index 320787e..4815db1 100755 --- a/irk +++ b/irk @@ -10,16 +10,24 @@ import json import socket import sys +import fileinput + +def send(target, message): + data = {"to": target, "privmsg" : message} + print(json.dumps(data)) + try: + s = socket.create_connection(("localhost", 6659)) + s.sendall(json.dumps(data)) + except socket.error, e: + sys.stderr.write("irkerd: server launch failed: %r\n" % e) target = sys.argv[1] if not "irc:" in target: target = "irc://chat.freenode.net/{0}".format(target) message = " ".join(sys.argv[2:]) message = message.decode('string_escape') -data = {"to": target, "privmsg" : message} -print(json.dumps(data)) -try: - s = socket.create_connection(("localhost", 6659)) - s.sendall(json.dumps(data)) -except socket.error, e: - sys.stderr.write("irkerd: server launch failed: %r\n" % e) +if message == '-': + for line in fileinput.input('-'): + send(target, line.rstrip('\n')) +else: + send(target, message)