New export format: markdown

This commit is contained in:
Lucas Cimon
2021-01-12 15:38:07 +01:00
parent 7709e58d64
commit 955e4b62d0
4 changed files with 32 additions and 8 deletions
+1 -1
View File
@@ -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.")
+17 -2
View File
@@ -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)