Skip to content

Commit

Permalink
refactor: make transfers use the rich bars properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone authored and eyeonus committed May 6, 2024
1 parent 8a9989b commit ca12c5f
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions tradedangerous/transfers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
if typing.TYPE_CHECKING:
import os # for PathLike
from .tradeenv import TradeEnv
from typing import Callable, Optional, Union
from collections.abc import Callable
from typing import Optional, Union


######################################################################
Expand Down Expand Up @@ -53,7 +54,7 @@ def download(
backup: bool = False,
shebang: Optional[Callable] = None,
chunkSize: int = 4096,
timeout: int = 90,
timeout: int = 30,
*,
length: Optional[Union[int, str]] = None,
session: Optional[requests.Session] = None,
Expand Down Expand Up @@ -168,18 +169,12 @@ def get_json_data(url, *, timeout: int = 90):
else:
totalLength = int(totalLength)
filename = get_filename_from_url(url)
progBar = pbar.Progress(totalLength, 25, style=pbar.DefaultBar, prefix=filename)
progBar = pbar.Progress(totalLength, 25, prefix=filename)

jsData = bytes()
for data in req.iter_content():
jsData += data
progBar.increment(
len(data),
postfix=lambda value, goal: \
" {}/{}".format(
makeUnit(value),
makeUnit(goal),
))
progBar.increment(len(data))
progBar.clear()

return json.loads(jsData.decode())

0 comments on commit ca12c5f

Please sign in to comment.