Skip to content

Instantly share code, notes, and snippets.

@Avlyssna
Created September 30, 2018 19:42
Show Gist options
  • Save Avlyssna/0fd3a38ccdba49260da682a9dec6013e to your computer and use it in GitHub Desktop.
Save Avlyssna/0fd3a38ccdba49260da682a9dec6013e to your computer and use it in GitHub Desktop.
# Standard library imports
from time import time
# Third-party imports
from humanfriendly import format_timespan
class Progress:
def __init__(self, total):
self.started_at = time()
self.total = total
self.current = 0
def step(self):
self.current += 1
seconds_passed = time() - self.started_at
percent = int(round(self.current / self.total, 2) * 100)
progress = round(percent * 0.5)
eta = format_timespan(round((seconds_passed / self.current) * (self.total - self.current)))
print('[{}{}] {}% ({}/{}) ETA {}'.format('#' * progress, ' ' * (50 - progress), percent, self.current, self.total, eta))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment