Hack Forums
[Python] Progress bar - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Progress bar (/showthread.php?tid=5909823)



Progress bar - Freed0m36 - Nov 19, 2018

I am writing a python web scraper which will use a document with a list of url's to scrape,
scrape the data I want and then write it to a file.
The list contains 24 url's and I am using "sleep" a few time in my functions to make sure not to overflow the websites with requests..
I want to implement a progress bar like "TQDM". but I am not sure how to use it.
Everywhere I look, they give examples with "for" loops and I'm not sure where to place that loop in my code to have a Global progress overview.

If anyone has experience with TQDM ( or any other progress bar module ) and the skills to solve my problem,
any help will be appreciated.


RE: Progress bar - Qismon - Nov 20, 2018

This should work fine.

Code
import progressbar
from time import sleep

bar = progressbar.ProgressBar(maxval=100, \
    widgets=[progressbar.Bar('=', '[', ']'), ' ', progressbar.Percentage()])
bar.start()
for i in xrange(100):
    bar.update(i+1)
    sleep(0.1)
bar.finish()



RE: Progress bar - DopplerAF - Nov 20, 2018

I don't have clear idea about what you are asking about but I have done something which might help you.

Code
from bs4 import BeautifulSoup
from urllib import request
import time
from progressbar import ProgressBar, Bar, Percentage

pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=100)

content = request.urlopen("https://www.youtube.com").read()
soup = BeautifulSoup(content, features="html.parser")
test_file = open("test.txt", "w")

for i in pbar(soup.find_all('a')):
    test_file.write(str(i.get("href")) + "\n")
    time.sleep(0.05)
test_file.close()



RE: Progress bar - PoP-Hacker - Nov 21, 2018

import time
import sys

toolbar_width = 40


sys.stdout.write("[%s]" % (" " toolbar_width))
sys.stdout.flush()
sys.stdout.write("\b"
(toolbar_width+1))

for i in range(toolbar_width):
time.sleep(0.1)

sys.stdout.write(">")
sys.stdout.flush()

sys.stdout.write("\n")


RE: Progress bar - StreetSquirrel - Nov 21, 2018

(Nov 21, 2018 12:03 PM)PoP-Hacker Wrote:  import time
import sys

toolbar_width = 40


sys.stdout.write("[%s]" % (" " toolbar_width))
sys.stdout.flush()
sys.stdout.write("\b"
(toolbar_width+1))

for i in range(toolbar_width):
   time.sleep(0.1)
   
   sys.stdout.write(">")
   sys.stdout.flush()

sys.stdout.write("\n")

[*code] [*/code]


RE: Progress bar - PoP-Hacker - Nov 21, 2018

(Nov 21, 2018 12:37 PM)StreetSquirrel Wrote:  [*code] [*/code]

?


RE: Progress bar - Infamia - Nov 21, 2018

(Nov 21, 2018 12:03 PM)PoP-Hacker Wrote:  import time
import sys

toolbar_width = 40


sys.stdout.write("[%s]" % (" " toolbar_width))
sys.stdout.flush()
sys.stdout.write("\b"
(toolbar_width+1))

for i in range(toolbar_width):
   time.sleep(0.1)
   
   sys.stdout.write(">")
   sys.stdout.flush()

sys.stdout.write("\n")

unnecessarily using `sys.stdout.write` is pointless.


RE: Progress bar - PoP-Hacker - Nov 22, 2018

(Nov 21, 2018 03:02 PM)Infamia Wrote:  unnecessarily using `sys.stdout.write` is pointless.

HAHA You not well done me but small problem in replay me