From 53fbe3f84076959e983a03fe424bbb054b52c8cb Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Wed, 10 Oct 2012 21:02:05 +0200 Subject: [PATCH] Support piping text to irk Usage: outcmd|irk target - Sending "-" is still possible by echo -|irk target - Signed-off-by: Eric S. Raymond --- irk | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) 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) -- 2.26.2