66
77from typing import Optional , Dict , Tuple
88from rich .progress import Progress , SpinnerColumn , TextColumn
9- from rich import console
109
1110from domaintools .api import API
1211from domaintools .exceptions import ServiceException
1312from domaintools .cli .utils import get_file_extension
1413
15- console = console .Console ()
16-
1714
1815class DTCLICommand :
1916 API_SUCCESS_STATUS = 200
@@ -129,6 +126,13 @@ def _get_domains_from_source(cls, source: str) -> Dict[str, str]:
129126 domains .extend ([row .get ("domain" ) or "" for row in reader ])
130127 else :
131128 domains .extend ([domain .strip () for domain in src .readlines ()])
129+
130+ total_domains_found = len (domains )
131+ if total_domains_found > 100 :
132+ raise typer .BadParameter (
133+ f"Domains in source file exceeds the maximum count of 100. Current source file domain count: { total_domains_found } "
134+ )
135+
132136 except FileNotFoundError :
133137 raise typer .BadParameter (f"File '{ source } ' not found." )
134138
@@ -198,13 +202,11 @@ def run(cls, name: str, params: Optional[Dict] = {}, **kwargs):
198202
199203 if isinstance (out_file , _io .TextIOWrapper ):
200204 # use rich `print` command to prettify the ouput in sys.stdout
201- print (output )
205+ print (response )
202206 else :
203207 # if it's a file then write
204208 out_file .write (output if output .endswith ("\n " ) else output + "\n " )
205- time .sleep (0.5 )
206-
207- name = typer .style (name , fg = typer .colors .CYAN , bold = True )
209+ time .sleep (0.25 )
208210 except Exception as e :
209211 if isinstance (e , ServiceException ):
210212 code = typer .style (getattr (e , "code" , 400 ), fg = typer .colors .BRIGHT_RED )
@@ -218,7 +220,7 @@ def run(cls, name: str, params: Optional[Dict] = {}, **kwargs):
218220
219221 reason = typer .style (_reason , bg = typer .colors .RED )
220222
221- err_msg_format = f"Error occured while fetching data from API: [{ code } ] Reason: { reason } "
223+ err_msg_format = f"Error occured while fetching data from the API: [{ code } ] Reason: { reason } "
222224 typer .echo (message = err_msg_format )
223225 else :
224226 typer .echo (message = e )
0 commit comments