11 assert sys.version_info >= (3, 5)
13 if len(sys.argv) != 2:
14 print("Usage: %s <channel>" % sys.argv[0])
17 fifo_dir = os.getenv('MTXBOT_FIFO_DIR', '/run/mtxbot')
18 fifo_path = "%s/%s" % (fifo_dir, sys.argv[1])
20 if not os.path.isdir(fifo_dir):
21 print("Fifo directory %s does not exist!" % fifo_dir, file=sys.stderr)
24 if not ( os.path.exists(fifo_path) and
25 stat.S_ISFIFO(os.stat(fifo_path).st_mode) ):
26 print("Channel %s does not exist!" % sys.argv[1], file=sys.stderr)
29 inBytes = sys.stdin.read().encode("UTF-8")
30 inB64 = base64.b64encode(inBytes)
32 for i in range(0, 10):
35 fifo = posix.open(fifo_path, posix.O_WRONLY | posix.O_NONBLOCK)
36 posix.write(fifo, inB64)
39 if e.errno == errno.ENXIO:
45 print("Error posting to channel %s!" % sys.argv[1], file=sys.stderr)