#!env python

import sys

import cloudtee
import cloudtee.cli


def read_stdin():

    def _read_chunk():
        return sys.stdin.readline()

    chunk = _read_chunk()
    while chunk:
        yield chunk
        chunk = _read_chunk()


if __name__ == "__main__":
    parser = cloudtee.cli.get_option_parser()    
    args = parser.parse_args()
    stream = cloudtee.WritableStream(args.host, args.port, args.topic)
    try:
        for chunk in read_stdin():
            stream.write(chunk)
            sys.stdout.write(chunk)
    except KeyboardInterrupt:
        stream.close()
