MCPcopy
hub / github.com/InstaPy/InstaPy / progress_tracker

Function progress_tracker

instapy/util.py:2300–2364  ·  view source on GitHub ↗

Provide a progress tracker to keep value updated until finishes

(current_value, highest_value, initial_time, logger)

Source from the content-addressed store, hash-verified

2298
2299
2300def progress_tracker(current_value, highest_value, initial_time, logger):
2301 """Provide a progress tracker to keep value updated until finishes"""
2302 if current_value is None or highest_value is None or highest_value == 0:
2303 return
2304
2305 try:
2306 real_time = time.time()
2307 progress_percent = int((current_value / highest_value) * 100)
2308 show_logs = Settings.show_logs
2309
2310 elapsed_time = real_time - initial_time
2311 elapsed_formatted = truncate_float(elapsed_time, 2)
2312 elapsed = (
2313 "{} seconds".format(elapsed_formatted)
2314 if elapsed_formatted < 60
2315 else "{} minutes".format(truncate_float(elapsed_formatted / 60, 2))
2316 )
2317
2318 eta_time = abs(
2319 (elapsed_time * 100) / (progress_percent if progress_percent != 0 else 1)
2320 - elapsed_time
2321 )
2322 eta_formatted = truncate_float(eta_time, 2)
2323 eta = (
2324 "{} seconds".format(eta_formatted)
2325 if eta_formatted < 60
2326 else "{} minutes".format(truncate_float(eta_formatted / 60, 2))
2327 )
2328
2329 tracker_line = "-----------------------------------"
2330 filled_index = int(progress_percent / 2.77)
2331 progress_container = (
2332 "[" + tracker_line[:filled_index] + "+" + tracker_line[filled_index:] + "]"
2333 )
2334 progress_container = (
2335 progress_container[: filled_index + 1].replace("-", "=")
2336 + progress_container[filled_index + 1 :]
2337 )
2338
2339 total_message = (
2340 "\r {0}/{1} {2} {3}% "
2341 "|> Elapsed: {4:20} "
2342 "|> ETA: {5:20} ".format(
2343 current_value,
2344 highest_value,
2345 progress_container,
2346 progress_percent,
2347 elapsed,
2348 eta,
2349 )
2350 )
2351
2352 if show_logs is True:
2353 sys.stdout.write(total_message)
2354 sys.stdout.flush()
2355
2356 except Exception as exc:
2357 if not logger:

Callers 4

get_active_usersFunction · 0.85
likers_from_photoFunction · 0.85
get_followersFunction · 0.85
get_followingFunction · 0.85

Calls 1

truncate_floatFunction · 0.85

Tested by

no test coverage detected