How to use the pytablewriter.MarkdownTableWriter function in pytablewriter

To help you get started, weโ€™ve selected a few pytablewriter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thombashi / pytablewriter / test / writer / text / test_markdown_writer.py View on Github external
),
    ),
]

exception_test_data_list = [
    Data(
        table="",
        indent=0,
        header=[],
        value=[],
        is_formatting_float=True,
        expected=ptw.EmptyTableDataError,
    )
]

table_writer_class = ptw.MarkdownTableWriter


def trans_func(value):
    if value is None:
        return ""
    if value is True:
        return "X"
    if value is False:
        return ""
    return value


class Test_MarkdownTableWriter_write_new_line(object):
    def test_normal(self, capsys):
        writer = table_writer_class()
        writer.write_null_line()
github chaincodelabs / bitcoinperf / runner / output.py View on Github external
def print_comparative_times_table(cfg, runs: GroupedRuns, pfile=sys.stdout):
    writer = pytablewriter.MarkdownTableWriter()
    vs_str = ("{}" + (" vs. {}" * (len(runs.target_names) - 1))).format(
        *runs.target_names)
    writer.header_list = ["bench name", "x", *runs.target_names]
    writer.value_matrix = []
    writer.margin = 1
    writer.stream = pfile

    std_results = get_standard_results(runs)
    important_commands = {}

    for bench_name, target_to_benchlist in runs.items():
        if 'ibd' in bench_name or 'reindex' in bench_name:
            important_commands[bench_name] = _condense_bitcoin_cmd(
                list(target_to_benchlist.items())[0][1].command)

    cmd_writer = pytablewriter.MarkdownTableWriter()
github blue-oil / blueoil / lmnet / executor / output_event.py View on Github external
df.loc[step, column_name] = value

    if steps:
        df = df[steps, :]

    df = df.sort_index(ascending=False)

    # index to column. and re-order column.
    df["step"] = df.index
    df = df[["step"] + columns]

    output_csv = os.path.join(output_dir, "{}.csv".format(output_file_base))
    df.to_csv(output_csv, index=False)

    output_md = os.path.join(output_dir, "{}.md".format(output_file_base))
    writer = pytablewriter.MarkdownTableWriter()
    writer.char_left_side_row = "|"  # fix for github
    writer.from_dataframe(df)

    with open(output_md, "w") as file_stream:
        writer.stream = file_stream
        writer.write_table()

    message = """
output success

output csv: {}
output md: {}
""".format(output_csv, output_md)

    print(message)
github Zackhardtoname / internships / convert_md.py View on Github external
def convert(filename, from_ext, to_ext):
    # provide index for the md file
    helpers.add_index_col(filename)

    indexed_filename = f"{filename}_temp.{from_ext}"
    writer = pytablewriter.MarkdownTableWriter()
    writer.from_csv(indexed_filename)

    with open(f"./{filename}.{to_ext}", "w") as f:
        writer.table_name = "Internships"
        writer.stream = f
        writer.write_table()
github thombashi / pytablewriter / examples / py / from_csv_file.py View on Github external
from textwrap import dedent

import pytablewriter


filename = "sample.csv"

with io.open(filename, "w", encoding="utf8") as f:
    f.write(dedent("""\
        "i","f","c","if","ifc","bool","inf","nan","mix_num","time"
        1,1.10,"aa",1.0,"1",True,Infinity,NaN,1,"2017-01-01 00:00:00+09:00"
        2,2.20,"bbb",2.2,"2.2",False,Infinity,NaN,Infinity,"2017-01-02 03:04:05+09:00"
        3,3.33,"cccc",-3.0,"ccc",True,Infinity,NaN,NaN,"2017-01-01 00:00:00+09:00"
        """))

writer = pytablewriter.MarkdownTableWriter()
writer.from_csv(filename)
writer.write_table()
github KhassTeam / Khaltoor / main.py View on Github external
def write_table(tracks, output_path):
    writer = pytablewriter.MarkdownTableWriter()
    writer.header_list = ['Title', 'Artist', 'Album', 'User', 'Added at']
    value_matrix = []
    for track in tracks:
        print(track['title'])
        cur = [
            get_md_link(track['title'], track['track_url']),
            ', '.join(map(lambda x: x['name'], track['artists'])),
            track['album']['name'],
            get_md_link(track['user']['name'], track['user']['url']),
            track['added_at'].strftime('%Y-%m-%d')
        ]
        value_matrix.append(cur)
    writer.value_matrix = value_matrix
    with open(output_path, 'w') as f:
        writer.stream = f
        writer.write_table()
github hugovk / pypistats / src / pypistats / __init__.py View on Github external
def _tabulate(data, format="markdown"):
    """Return data in specified format"""

    format_writers = {
        "markdown": MarkdownTableWriter,
        "rst": RstSimpleTableWriter,
        "html": HtmlTableWriter,
    }

    writer = format_writers[format]()
    if format != "html":
        writer.margin = 1

    if isinstance(data, dict):
        header_list = list(data.keys())
        writer.value_matrix = [data]
    else:  # isinstance(data, list):
        header_list = sorted(set().union(*(d.keys() for d in data)))
        writer.value_matrix = data

    # Move downloads last
github thombashi / pytablewriter / examples / py / stream / configure_stream.py View on Github external
#!/usr/bin/env python
# encoding: utf-8

"""
.. codeauthor:: Tsuyoshi Hombashi 
"""

from __future__ import print_function

import pytablewriter
import six


writer = pytablewriter.MarkdownTableWriter()
writer.table_name = "zone"
writer.headers = ["zone_id", "country_code", "zone_name"]
writer.value_matrix = [
    ["1", "AD", "Europe/Andorra"],
    ["2", "AE", "Asia/Dubai"],
    ["3", "AF", "Asia/Kabul"],
    ["4", "AG", "America/Antigua"],
    ["5", "AI", "America/Anguilla"],
]

# writer instance writes a table to stdout by default
writer.write_table()

# change the stream to a string buffer to get the output as a string
# you can also get tabular text by using dumps method
writer.stream = six.StringIO()