diff options
author | davidovski <david@davidovski.xyz> | 2021-11-09 17:36:30 +0000 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2021-11-09 17:36:30 +0000 |
commit | a4618ee489a1cc393e195d61e965bd41885e8f14 (patch) | |
tree | db267730583844683979932323913cfab1494889 /src/util.py | |
parent | a8c82c3abbd0a0a1b9d82d126872ab989bb263aa (diff) |
synced packages from repos to list
Diffstat (limited to 'src/util.py')
-rw-r--r-- | src/util.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/util.py b/src/util.py new file mode 100644 index 0000000..de05b08 --- /dev/null +++ b/src/util.py @@ -0,0 +1,37 @@ +import shutil +import requests +import colors +import time +import os + +def loading_bar(completed, total, text, + unit=""): + + columns, rows = shutil.get_terminal_size((80, 20)) + + count = f"[{completed}{unit}/{total}{unit}]" + + spaces = columns - (len(count) + len(text)) + info = text + "".join([" " for i in range(spaces)]) + count + + + reset_at = int((completed/total)*len(info)) if total > 0 else 0 + info = "".join([info[i] + (colors.RESET if i == reset_at else "") for i in range(len(info))]) + + print(colors.BLACK + colors.BG_GREEN + info, end="\r") + + + + +def curl(url): + r = requests.get(url) + return r.status_code, r.text + +def mkdir(path): + if not os.path.exists(path): + os.makedirs(path) + +if __name__ == "__main__": + for i in range(1000): + loading_bar(i, 1000, "it is loading...") + time.sleep(0.01) |