def test_time(self):
     with patch('sys.stdout', new=io.StringIO()) as out:
         bar = ProgressBar(5,
                           time_format='hh hours, mm minutes, ss seconds')
         time.sleep(bar.update_period * 1.2)
         bar.stop()
         self.assertTrue(
             '00 hours, 00 minutes, 00 seconds' in out.getvalue())
         bar = ProgressBar(5,
                           time_format='hh hours, mm minutes, ss seconds',
                           use_eta=True)
         bar.iter()
         time.sleep(bar.update_period * 1.2)
         bar.stop()
         self.assertTrue(
             '00 hours, 00 minutes, 00 seconds/00 hours, 00 minutes, 00 seconds'
             in out.getvalue())
    def test_eta(self):
        with patch('sys.stdout', new=io.StringIO()) as out:
            bar = ProgressBar(300, use_eta=True)
            for x in range(3):
                time.sleep(0.2)
                bar.iter()
            time.sleep(bar.update_period)
            bar.stop()
            eta = re.findall(f'\d\d:\d\d', out.getvalue())[-1]
            self.assertTrue(eta in [f'01:0{x}' for x in range(10)])

            bar = ProgressBar(5,
                              use_eta=True,
                              eta_format='hh hours, mm minutes, ss seconds')
            bar.iter()
            time.sleep(bar.update_period * 1.2)
            bar.stop()
            self.assertTrue(
                '/00 hours, 00 minutes, 00 seconds' in out.getvalue())
Esempio n. 3
0
    def delete(self, UIDs):
        """
        Move specified emails to Trash box

        Args:
            UIDs(list(int)): list of email unique identifiers (UID) that have been marked for deletion

        """
        total = len(UIDs)
        bar = ProgressBar(total,
                          use_eta=True,
                          bar_length=70,
                          spinner_type='db')
        for message in UIDs:
            try:
                self.server.add_gmail_labels(message, '\Trash', silent=True)
                bar.iter(' Moved to Trash')
            except:
                bar.stop()
Esempio n. 4
0
def Downloader(dlList):
    global failedImg

    succeeded = 0
    failed = []
    # 初始化进度条
    bar = ProgressBar(len(dlList), prefix="Downloading", bar_length=60)
    try:
        for num in dlList:
            try:
                imgUrl = getImgURL(num)
                imgName = imgUrl.split("/")[-1]
                imgDL(imgUrl, DlPath.format(imgName))

                sleep(2)
                succeeded += 1
            except:  # 请求错误(超时)处理
                failed.append(num)
                failedImg.append(num)
                sleep(0.5)

            bar.iter()
    except:  # 迭代结束
        bar.stop()
        exit(0)

    bar.wait()
    # 本次下载内容总览
    print("下载完成! | Download Finished!")
    print("本次下载 | You downloaded :")
    print("成功 | Succeeded: " + str(succeeded))
    print("失败 | Failed: " + str(len(failed)))

    if len(failed) == 0:
        exit(0)
    else:
        toDlFailed = input(
            "是否重新下载错误的图片? | Wanna download imgs failed? (y / n) ")
        # if toDlFailed == "y":
        failedImg = failed
        return True
Esempio n. 5
0
from awesome_progress_bar import ProgressBar
import time

total = 133
try:
    bar = ProgressBar(total)
    for x in range(total):
        time.sleep(0.1)
        bar.iter()
except:
    bar.stop()
bar.wait()
time_passed = bar.get_time_passed()
print(f'Total time passed: {time_passed}')
# Progress: |==================================== 00:15 =====================================| 100.00%
# Total time passed: 00:15

try:
    bar = ProgressBar(total, 'Prefix', 'Suffix', use_eta=True)
    for x in range(total):
        time.sleep(0.1)
        bar.iter()
except:
    bar.stop()
bar.wait()
time_passed = bar.get_time_passed(False)
print(f'Total seconds passed: {time_passed:.4f}')
# Prefix: |================================== 00:15 ==================================| 100.00% Suffix
# Total seconds passed: 14.5497

# No need to use try/catch without thread