Python progress bar and downloads

前端 未结 10 1176
庸人自扰
庸人自扰 2020-11-28 02:28

I have a python script that launches a URL that is a downloadable file. Is there some way to have python use commandline to display the download progress as oppose to launch

10条回答
  •  悲哀的现实
    2020-11-28 02:52

    #ToBeOptimized - Baseline If you would like to puzzle your brain and hand craft the logic

    # Define Progress Bar function

    def print_progressbar(total,current,barsize=60):
        progress=int(current*barsize/total)
        completed= str(int(current*100/total)) + '%'
        print('[' , chr(9608)*progress,' ',completed,'.'*(barsize-progress),'] ',str(i)+'/'+str(total), sep='', end='\r',flush=True)
    

    # Sample Code

    total= 6000
    barsize=60
    print_frequency=max(min(total//barsize,100),1)
    print("Start Task..",flush=True)
    for i in range(1,total+1):
      if i%print_frequency == 0 or i == 1:
        print_progressbar(total,i,barsize)
    print("\nFinished",flush=True)
    

    # Snapshot of Progress Bar :

    Below lines are for illustrations only. In command prompt you will see single progress bar showing incremental progress.

    [ 0%............................................................] 1/6000
    
    [██████████ 16%..................................................] 1000/6000
    
    [████████████████████ 33%........................................] 2000/6000
    
    [██████████████████████████████ 50%..............................] 3000/6000
    
    [████████████████████████████████████████ 66%....................] 4000/6000
    
    [██████████████████████████████████████████████████ 83%..........] 5000/6000
    
    [████████████████████████████████████████████████████████████ 100%] 6000/6000
    

    Good Luck and Enjoy!

提交回复
热议问题