Python Forum
How can I add a progress bar for my software?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I add a progress bar for my software?
#8
(Nov-15-2019, 09:43 PM)aquerci Wrote: ok, it's simple, but what about if I have many "for" loops in my script? most of my code is composed by many "for" loops. maybe I could apply tqdm for all of them, but how can I do it and at the same time have an unique loading bar?
You add to where it make sense usually one or two bar's,or it can soon get confusing to watch.
To test my code that poster link to,to see if it still work as it's 1,5 year sine i wrote it.
This is a example of two bar's working together,one main that stop at 72(all planes downloaded).
Then a bar for each plane type eg 18/18 will count 1 on the way to 72(all planes).
from bs4 import BeautifulSoup
import requests
from tqdm import tqdm, trange
from itertools import islice
 
def all_planes():
    '''Generate url links for all planes'''
    url = 'http://web.archive.org/web/20041225023002/http://www.projectai.com:80/libraries/acfiles.php?cat=6'
    url_get = requests.get(url)
    soup = BeautifulSoup(url_get.content, 'lxml')
    td = soup.find_all('td', width="50%")
    plain_link = [link.find('a').get('href') for link in td]
    for ref in tqdm(plain_link):
         url_file_id = 'http://web.archive.org/web/20041114195147/http://www.projectai.com:80/libraries/{}'.format(ref)
         yield url_file_id
 
def download(all_planes):
    '''Download zip for 1 plain,feed with more url download all planes'''
    # A_300 = next(all_planes())  # Test with first link
    last_3 = islice(all_planes(), 65, 72)
    for plane_url in last_3:
        url_get = requests.get(plane_url)
        soup = BeautifulSoup(url_get.content, 'lxml')
        td = soup.find_all('td', class_="text", colspan="2")
        zip_url = 'http://web.archive.org/web/20041108022719/http://www.projectai.com:80/libraries/download.php?fileid={}'
        for item in tqdm(td):
            zip_name = item.text
            zip_number = item.find('a').get('href').split('=')[-1]
            with open(zip_name, 'wb')  as f_out:
                down_url = requests.get(zip_url.format(zip_number))
                f_out.write(down_url.content)
 
if __name__ == '__main__':
    download(all_planes)
[Image: WbprLx.png]
Reply


Messages In This Thread
RE: How can I add a progress bar for my software? - by snippsat - Nov-16-2019, 12:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Progress bar bnadir55 1 1,841 Apr-11-2022, 01:52 PM
Last Post: deanhystad
  Progress Indicator for Xmodem 0.4.6 KenHorse 1 1,984 Jan-30-2021, 07:12 PM
Last Post: bowlofred
  wget progress bar anasrocks 1 4,744 Jun-06-2019, 03:12 PM
Last Post: heiner55
  Progress Finished Question malonn 32 17,682 May-23-2018, 02:43 AM
Last Post: malonn
  how to progress with py jakegold98 1 2,641 Dec-05-2017, 02:58 AM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020