def download_command(ctx: click.Context, start: datetime.datetime, stop: datetime.datetime, float_step: float) -> None: api_client = APIClient.csv() step = datetime.timedelta(days=float_step) dfs = [] while stop > start: start += step rsp = api_client.get( f"byperiod/{ceil(step.total_seconds())}/{int(start.timestamp())}") dfs.append(pd.read_csv(StringIO(get_text(rsp)), sep=";")) df = pd.concat(dfs) with StringIO() as buffer: df.to_csv(buffer, sep=";", index=False) click.echo(buffer.getvalue())
def download_command( ctx: click.Context, start: datetime.datetime, stop: datetime.datetime, float_step: float ) -> None: api_client = APIClient.csv(context=ctx.obj) step = datetime.timedelta(days=float_step) dfs = [] while stop > start: start += step rsp = api_client.get(f"byperiod/{ceil(step.total_seconds())}/{int(start.timestamp())}") dfs.append(pd.read_csv(StringIO(get_text(rsp)), sep=";")) df = pd.concat(dfs) with StringIO() as buffer: # set line_terminator to ensure universal newline support for all the OS df.to_csv(buffer, sep=";", index=False, line_terminator="\n") click.echo(buffer.getvalue())