summaryrefslogtreecommitdiff
path: root/src/util.py
blob: de05b087fb431974c0dea225359dd255aef68e56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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)