hhh
import time import sys def simulate_upload(file_size_mb, upload_speed_mbps): """ Simulates an upload process and displays progress with time remaining and percentage. :param file_size_mb: Size of the file in megabytes :param upload_speed_mbps: Upload speed in megabits per second """ total_seconds = (file_size_mb * 8) / upload_speed_mbps # Convert MB to Mb and divide by speed total_steps = 100 # Progress steps (percent) step_duration = total_seconds / total_steps # Time per percent step print("Starting upload...") for step in range(1, total_steps + 1): time.sleep(step_duration) # Simulate time for each step percent_complete = step # Current percent completed time_remaining = (total_steps - step) * step_duration # Time remaining in seconds # Convert time remaining to minutes and seconds minutes, seconds = divmod(int(time_remaining), 60) # Display progress sys.stdout.write(f"\rProgress: {percent_complete}% | Time Remaining: {minutes}m {seconds}s") sys.stdout.flush() print("\nUpload complete!") # Example Usage: file_size_mb = 100 # File size in MB upload_speed_mbps = 10 # Upload speed in Mbps simulate_upload(file_size_mb, upload_speed_mbps)
Kommentare
Kommentar veröffentlichen