Ejemplo n.º 1
0
    writer = None

    try:
        # ------------------------------------------------------------------------------------------------------------
        # cmd...

        cmd = CmdCSVWriter()

        if cmd.verbose:
            print("csv_writer: %s" % cmd, file=sys.stderr)
            sys.stderr.flush()

        # ------------------------------------------------------------------------------------------------------------
        # resources...

        writer = CSVWriter(cmd.filename, cmd.append)

        if cmd.verbose:
            print("csv_writer: %s" % writer, file=sys.stderr)

        # ------------------------------------------------------------------------------------------------------------
        # run...

        for line in sys.stdin:
            datum = line.strip()

            if datum is None:
                break

            writer.write(datum)
Ejemplo n.º 2
0
    def construct(cls, lower, upper, file_prefix, form):
        file_name = file_prefix + cls.__infix(form, lower) + cls.__infix(
            form, upper) + '.csv'
        writer = CSVWriter(file_name)

        return CSVCollatorBin(lower, upper, writer)
Ejemplo n.º 3
0
# reference row...
jstr1 = '{"rec": "2016-09-27T13:29:52.947+01:00", "val": {"opc_n2": {"pm1": 1, "pm2p5": 2, "pm10": 3, ' \
        '"per": 4, "bin1": {"a": 5, "b": 6}, "bin2": [7, 8], "mtf1": 9}}}'
print("jstr1: %s" % jstr1)
print("-")

# missing value...
jstr2 = '{"rec": "2016-09-27T13:29:52.947+01:00", "val": {"opc_n2": {"pm1": 1, "pm2p5": 2, "pm10": 3, ' \
        '"bin1": {"a": 5, "b": 6}, "bin2": [7, 8], "mtf1": 9}}}'
print("jstr2: %s" % jstr2)
print("-")

# extra value...
jstr3 = '{"rec": "2016-09-27T13:29:52.947+01:00", "val": {"opc_n2": {"pm1": 1, "pm2p5": 2, "pm10": 3, ' \
        '"per": 4, "xxx": 999, "bin1": {"a": 5, "b": 6}, "bin2": [7, 8], "mtf1": 9}}}'
print("jstr3: %s" % jstr3)
print("=")

# --------------------------------------------------------------------------------------------------------------------

writer = CSVWriter()
print(writer)
print("-")

writer.write(jstr1)
writer.write(jstr2)
writer.write(jstr3)
print("-")

print(writer)
Ejemplo n.º 4
0
    csv = None

    try:
        # ------------------------------------------------------------------------------------------------------------
        # cmd...

        cmd = CmdCSVWriter()

        if cmd.verbose:
            print(cmd, file=sys.stderr)
            sys.stderr.flush()

        # ------------------------------------------------------------------------------------------------------------
        # resources...

        csv = CSVWriter(cmd.filename, cmd.cache, cmd.append)

        if cmd.verbose:
            print(csv, file=sys.stderr)

        # ------------------------------------------------------------------------------------------------------------
        # run...

        for line in sys.stdin:
            datum = line.strip()

            if datum is None:
                break

            csv.write(datum)
Ejemplo n.º 5
0
    cmd = CmdCSVWriter()

    if not cmd.is_valid():
        cmd.print_help(sys.stderr)
        exit(2)

    if cmd.verbose:
        print("csv_writer: %s" % cmd, file=sys.stderr)
        sys.stderr.flush()

    try:
        # ------------------------------------------------------------------------------------------------------------
        # resources...

        writer = CSVWriter(filename=cmd.filename,
                           append=cmd.append,
                           exclude_header=cmd.exclude_header)

        if cmd.verbose:
            print("csv_writer: %s" % writer, file=sys.stderr)

        # ------------------------------------------------------------------------------------------------------------
        # run...

        for line in sys.stdin:
            jstr = line.strip()

            writer.write(jstr)

            # echo...
            if cmd.echo: