Skip to content

Commit

Permalink
BITMAKER-3178: Add option to output data in TSV format (#34)
Browse files Browse the repository at this point in the history
* Add option to output data in TSV format
* Bump version: 0.2.1 → 0.2.2
  • Loading branch information
mgonnav committed May 22, 2023
1 parent d74d861 commit 881750b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.1
current_version = 0.2.2
commit = True
tag = True
tag_name = {new_version}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1 align="center"> estela CLI </h1>

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![version](https://img.shields.io/badge/version-0.2.1-blue)](https://github.com/bitmakerla/estela-cli)
[![version](https://img.shields.io/badge/version-0.2.2-blue)](https://github.com/bitmakerla/estela-cli)
[![python-version](https://img.shields.io/badge/python-v3.10-orange)](https://www.python.org)


Expand Down
2 changes: 1 addition & 1 deletion estela_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__all__ = ["__version__"]

__version__ = "0.2.1"
__version__ = "0.2.2"
6 changes: 4 additions & 2 deletions estela_cli/data/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

SHORT_HELP = "Retrieve data from a job"
ALLOWED_DATA_TYPES = ["items", "requests", "logs", "stats"]
ALLOWED_DATA_FORMATS = ["json", "csv"]
ALLOWED_DATA_FORMATS = ["json", "csv", "tsv"]


@click.command(short_help=SHORT_HELP)
Expand Down Expand Up @@ -67,7 +67,9 @@ def estela_command(
) as progress_bar:
next_chunk = None
while True:
response = estela_client.get_spider_job_data(pid, sid, jid, datatype, next_chunk)
response = estela_client.get_spider_job_data(
pid, sid, jid, datatype, next_chunk
)
chunk = response.get("results")
save_chunk_data(tmp_filename, chunk)
progress_bar.update(len(chunk))
Expand Down
5 changes: 3 additions & 2 deletions estela_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ def save_data(filename, tmp_filename, format):

if format == "json":
os.rename(tmp_filename, filename)
elif format == "csv":
elif format == "csv" or format == "tsv":
delimiter = "," if format == "csv" else "\t"
with open(tmp_filename, "r", encoding="utf-8") as F:
data = json.load(F)
with open(filename, "w", encoding="utf-8") as F:
keys = data[0].keys()
writer = csv.DictWriter(F, fieldnames=keys)
writer = csv.DictWriter(F, delimiter=delimiter, fieldnames=keys)
writer.writeheader()
for row in data:
writer.writerow({k: v for k, v in row.items() if k in keys})
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="estela",
version="0.2.1",
version="0.2.2",
description="Estela Command Line Interface",
packages=find_packages(),
entry_points={
Expand Down

0 comments on commit 881750b

Please sign in to comment.