Created
September 30, 2018 19:42
-
-
Save Avlyssna/0fd3a38ccdba49260da682a9dec6013e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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