Skip to content

Commit f3a15c6

Browse files
committed
IDEV-2020: Adjust cli implementation
1 parent 18ffd9c commit f3a15c6

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

domaintools/cli/api.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from rich.progress import Progress, SpinnerColumn, TextColumn
1010

1111
from domaintools.api import API
12-
from domaintools.constants import Endpoint, OutputFormat
12+
from domaintools.constants import Endpoint, FEEDS_PRODUCTS_LIST, OutputFormat
1313
from domaintools.cli.utils import get_file_extension
1414
from domaintools.exceptions import ServiceException
1515
from domaintools._version import current as version
@@ -110,6 +110,8 @@ def args_to_dict(*args) -> Dict:
110110
def _get_formatted_output(cls, cmd_name: str, response, out_format: str = "json"):
111111
if cmd_name in ("available_api_calls",):
112112
return "\n".join(response)
113+
if response.product in FEEDS_PRODUCTS_LIST:
114+
return "\n".join([data for data in response.response()])
113115
return str(getattr(response, out_format) if out_format != "list" else response.as_list())
114116

115117
@classmethod
@@ -227,7 +229,10 @@ def run(cls, name: str, params: Optional[Dict] = {}, **kwargs):
227229

228230
if isinstance(out_file, _io.TextIOWrapper):
229231
# use rich `print` command to prettify the ouput in sys.stdout
230-
print(response)
232+
if response.product in FEEDS_PRODUCTS_LIST:
233+
print(output)
234+
else:
235+
print(response)
231236
else:
232237
# if it's a file then write
233238
out_file.write(output if output.endswith("\n") else output + "\n")

domaintools_async/__init__.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,9 @@ async def _make_async_request(self, session):
5252
patch_data.update(self.api.extra_request_params)
5353
results = await session.patch(url=self.url, json=patch_data)
5454
elif self.product in FEEDS_PRODUCTS_LIST:
55-
parameters = deepcopy(self.kwargs)
56-
parameters.pop("output_format", None)
57-
parameters.pop(
58-
"format", None
59-
) # For some unknownn reasons, even if "format" is not included in the cli params for feeds endpoint, it is being populated thus we need to remove it. Happens only if using CLI.
60-
headers = {}
61-
if self.kwargs.get("output_format", OutputFormat.JSONL.value) == OutputFormat.CSV.value:
62-
parameters["headers"] = int(bool(self.kwargs.get("headers", False)))
63-
headers["accept"] = HEADER_ACCEPT_KEY_CSV_FORMAT
64-
65-
header_api_key = parameters.pop("X-Api-Key", None)
66-
if header_api_key:
67-
headers["X-Api-Key"] = header_api_key
68-
55+
session_params = self._get_session_params()
56+
parameters = session_params.get("parameters")
57+
headers = session_params.get("headers")
6958
results = await session.get(url=self.url, params=parameters, headers=headers, **self.api.extra_request_params)
7059
else:
7160
results = await session.get(url=self.url, params=self.kwargs, **self.api.extra_request_params)

0 commit comments

Comments
 (0)