rsalmei / alive-progress

A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
MIT License
5.53k stars 206 forks source link

bar, set to 100% finished even if only passes 80% #39

Closed maborak closed 4 years ago

maborak commented 4 years ago

Hello, first of all. Congrats for an excellent job.

Second:

I am using the package in a scrapping ebook project where the total of items is not accurate, so at the end the progress bar will show only 80%/100% and end the iteration process

And this is ok. But i want to know if there is a way to tell to bar() that the process is completed and mark it as 100%/100%

Is that possible?

with alive_bar(total_predicted_items) as bar:
    for page in nop:
        lr.process_page(page_number=page, progressbar=lambda: bar("Processing..."))
    bar() #<-- I want to mark it as 100%

Thank you

rsalmei commented 4 years ago

Hello, first of all. Congrats for an excellent job.

Hello man, thank you! Appreciated.

In your example code, since you send pages one by one, I think it would cleaner if you'd put the bar() call just after the process_page.

Anyway, yes, there is a way, just use the manual mode! With it you can put the bar in whatever position you like.

So before exiting the alive_bar context, you send 100% to it! Something like this:

with alive_bar(total_predicted_items, manual=True) as bar:
    bar(0., "Processing...")  # acts as a default message.
    for page in nop:  # I'm assuming `page` is an int, since you pass it to `page_number` below.
        lr.process_page(page_number=page)
        bar(page / total_predicted_items)
    bar(1.) # marks it to 100% before leaving the context.

That's it! You should even continue to send the predicted total to the starting alive_bar call, even being seammingly unnecessary, to still get the throughput and ETA widgets.

You're welcome 👍.

rsalmei commented 4 years ago

Hey @maborak, have you had the chance to test it? Did it work now for you?

rsalmei commented 4 years ago

Closing this, please reopen if needed 👍