-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconsole_progress_bars
More file actions
77 lines (57 loc) · 1.7 KB
/
console_progress_bars
File metadata and controls
77 lines (57 loc) · 1.7 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import time, sys
if sys.version[0] == '2':
range = xrange
def flush():
if sys.version[0] == '2':
sys.stdout.flush()
def progressbar_num():
for num in range(101):
time.sleep(.1)
sys.stdout.write("\r{}%".format(num)) # or print >> sys.stdout, "\r%d%%" %i,
flush()
print('')
def progressbar_disp():
display_char = '#'
for num in range(101):
time.sleep(.1)
sys.stdout.write("\r[{0}] {1}%".format(int(num/3)*display_char, num))
flush()
print('')
def progressbar_disp_full():
display_char = '#'
incomplete_char = ' '
for num in range(101):
spacer = int(33-int(num/3)) * incomplete_char
filler = int(num/3)*display_char
time.sleep(.1)
sys.stdout.write("\r[{0}{1}] {2}%".format(filler, spacer, num))
flush()
print('')
progressbar_num()
progressbar_disp()
progressbar_disp_full()
####################################
#insert progress value sparadically throughout script
import sys
import time
def progress(count, suffix='', total=100, complete='=', incomplete='-', bar_len=60):
filled_len = int(round(bar_len * count / float(total)))
percents = round(100.0 * count / float(total), 1)
bar = complete * filled_len + incomplete * (bar_len - filled_len)
sys.stdout.write(f'[{bar}] {percents}% ...{suffix}\r')
sys.stdout.flush()
def task():
time.sleep(1)
def script():
progress(0,'running task 1')
task()
progress(20,'running task 2')
task()
progress(40,'running task 3')
task()
progress(60,'running task 4')
task()
progress(80,'running task 5')
task()
progress(100, ' complete ')
script()