New export format: markdown
parent
7709e58d64
commit
955e4b62d0
|
|
@ -43,7 +43,7 @@ pass_config = click.make_pass_decorator(Config)
|
|||
@click.option(
|
||||
"-f",
|
||||
"--format",
|
||||
type=click.Choice(["csv", "json", "excel", "html", "sqlite"]),
|
||||
type=click.Choice(["csv", "excel", "html", "json", "markdown", "sqlite"]),
|
||||
help="Output file format.",
|
||||
)
|
||||
@click.option("-z", "--zip", is_flag=True, help="Create ZIP archive.")
|
||||
|
|
|
|||
|
|
@ -634,6 +634,21 @@ class Table(object):
|
|||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(html_string)
|
||||
|
||||
def to_markdown(self, path, **kwargs):
|
||||
"""Writes Table to a Markdown file.
|
||||
|
||||
For kwargs, check :meth:`pandas.DataFrame.to_markdown`.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
path : str
|
||||
Output filepath.
|
||||
|
||||
"""
|
||||
md_string = self.df.to_markdown(**kwargs)
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(md_string)
|
||||
|
||||
def to_sqlite(self, path, **kwargs):
|
||||
"""Writes Table to sqlite database.
|
||||
|
||||
|
|
@ -715,7 +730,7 @@ class TableList(object):
|
|||
path : str
|
||||
Output filepath.
|
||||
f : str
|
||||
File format. Can be csv, json, excel, html and sqlite.
|
||||
File format. Can be csv, excel, html, json, markdown or sqlite.
|
||||
compress : bool
|
||||
Whether or not to add files to a ZIP archive.
|
||||
|
||||
|
|
@ -728,7 +743,7 @@ class TableList(object):
|
|||
|
||||
kwargs = {"path": path, "dirname": dirname, "root": root, "ext": ext}
|
||||
|
||||
if f in ["csv", "json", "html"]:
|
||||
if f in ["csv", "html", "json", "markdown"]:
|
||||
self._write_file(f=f, **kwargs)
|
||||
if compress:
|
||||
self._compress_dir(**kwargs)
|
||||
|
|
|
|||
3
setup.py
3
setup.py
|
|
@ -20,7 +20,8 @@ requires = [
|
|||
'openpyxl>=2.5.8',
|
||||
'pandas>=0.23.4',
|
||||
'pdfminer.six>=20200726',
|
||||
'PyPDF2>=1.26.0'
|
||||
'PyPDF2>=1.26.0',
|
||||
'tabulate'
|
||||
]
|
||||
|
||||
cv_requires = [
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ def test_cli_output_format():
|
|||
cli,
|
||||
["--format", "json", "--output", outfile, "stream", infile],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert result.exit_code == 0, f"Output: {result.output}"
|
||||
|
||||
# excel
|
||||
outfile = os.path.join(tempdir, "health.xlsx")
|
||||
|
|
@ -131,7 +131,7 @@ def test_cli_output_format():
|
|||
cli,
|
||||
["--format", "excel", "--output", outfile, "stream", infile],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert result.exit_code == 0, f"Output: {result.output}"
|
||||
|
||||
# html
|
||||
outfile = os.path.join(tempdir, "health.html")
|
||||
|
|
@ -139,7 +139,15 @@ def test_cli_output_format():
|
|||
cli,
|
||||
["--format", "html", "--output", outfile, "stream", infile],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert result.exit_code == 0, f"Output: {result.output}"
|
||||
|
||||
# markdown
|
||||
outfile = os.path.join(tempdir, "health.md")
|
||||
result = runner.invoke(
|
||||
cli,
|
||||
["--format", "markdown", "--output", outfile, "stream", infile],
|
||||
)
|
||||
assert result.exit_code == 0, f"Output: {result.output}"
|
||||
|
||||
# zip
|
||||
outfile = os.path.join(tempdir, "health.csv")
|
||||
|
|
@ -155,7 +163,7 @@ def test_cli_output_format():
|
|||
infile,
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert result.exit_code == 0, f"Output: {result.output}"
|
||||
|
||||
|
||||
def test_cli_quiet():
|
||||
|
|
|
|||
Loading…
Reference in New Issue