Created
September 2, 2018 16:19
-
-
Save gabefair/299f139767851d26b2a8a909404a25bb to your computer and use it in GitHub Desktop.
How I monitor progress in python
This file contains hidden or 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
import sys, os, datetime | |
from time import time | |
def update_progress(total_imported, skipped_files, current_location): | |
text = str(total_imported) + "/" + str(total_imported+skipped_files) + " imported. Looking in folder: " + current_location | |
sys.stdout.write('\r' + text) | |
sys.stdout.flush() | |
def main(): | |
start_time = datetime.datetime.fromtimestamp(time()) | |
print("Starting program with the following parameters: " + str(sys.argv)) | |
base_path = os.path.split(os.path.abspath(os.path.realpath(sys.argv[0])))[0] | |
update_progress(total_imported, skipped_files, base_path) | |
end_time = datetime.datetime.fromtimestamp(time()) | |
total_time = dateutil.relativedelta.relativedelta(end_time, start_time) | |
print "\nImport completed in: %d days, %d hours, %d minutes and %d seconds" % (total_time.days, total_time.hours, total_time.minutes, total_time.seconds) | |
if __name__ == '__main__': | |
os.system('mode con: cols=150 lines=8') | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment