2 # Illustrates how to test irkerd.
4 # First argument must be a channel URL. If it does not begin with "irc",
5 # the base URL for freenode is prepended.
7 # -k option kills irkerd if irk hard to spawn one.
9 # Second argument must be a payload string. Standard C-style escapes
10 # such as \n and \t are decoded.
21 def send(target, message):
22 data = {"to": target, "privmsg" : message}
23 #print(json.dumps(data))
25 s = socket.create_connection(("localhost", 6659))
26 s.sendall(json.dumps(data))
27 except socket.error, e:
28 sys.stderr.write("irkerd: write to server failed: %r\n" % e)
30 if __name__ == "__main__":
31 (options, arguments) = getopt.getopt(sys.argv[1:], "k", )
33 for (opt, val) in options:
37 # Spawn an irkerd instance if none is running.
39 # irkerd might already be running
40 s = socket.create_connection(("localhost", 6659))
43 # If it isn't, spawn an instance
44 print "Spawning an irker instance..."
45 irkerd = subprocess.Popen("irkerd", shell=True)
49 if not "irc:" in target:
50 target = "irc://chat.freenode.net/{0}".format(target)
51 message = " ".join(arguments[1:])
52 message = message.decode('string_escape')
54 for line in fileinput.input('-'):
55 send(target, line.rstrip('\n'))
62 print "...terminated."