Skip to content

Instantly share code, notes, and snippets.

@lcrs
Last active November 21, 2020 01:18
Show Gist options
  • Save lcrs/966928578363dd2c9bb4a4ff98be2ee0 to your computer and use it in GitHub Desktop.
Save lcrs/966928578363dd2c9bb4a4ff98be2ee0 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# Prints a progress bar and stats for a folder filling with files
# Pass the path and the total expected count, like:
# ./progress.py /path/to/somewhere/ 900
# |UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU | 62% 157/250 0.2fps 6.4spf eta0:09:57
# TODO:
# o Data rate stats
# o Take a fragment of shell script for custom counting
import os, sys, time, datetime
def countem(f):
dentries = os.listdir(f)
count = len(dentries)
return count;
folder = sys.argv[1]
target = int(sys.argv[2])
counts = []
while(True):
counts.append(countem(folder))
percent = 100.0 * float(counts[-1]) / float(target)
speed = 0.0
per = 0.0
eta = 0
try:
speed = (counts[-1] - counts[0]) / float(len(counts))
per = 1.0/speed;
eta = (target - counts[-1]) / speed
except:
pass
td = datetime.timedelta(seconds=int(eta))
bar = '|' + ('U' * int(percent/2)) + (' ' * (50-int(percent/2))) + '| '
print(bar + "%d%s %d/%d %.1f%s %.1f%s eta%s" % (int(percent), '%', counts[-1], target, speed, 'fps', per, 'spf', str(td)))
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment