(
current,
total,
bot,
ud_type,
message,
start
)
| 9 | |
| 10 | |
| 11 | async def progress_for_pyrogram( |
| 12 | current, |
| 13 | total, |
| 14 | bot, |
| 15 | ud_type, |
| 16 | message, |
| 17 | start |
| 18 | ): |
| 19 | now = time.time() |
| 20 | diff = now - start |
| 21 | if round(diff % 10.00) == 0 or current == total: |
| 22 | percentage = current * 100 / total |
| 23 | status = DOWNLOAD_LOCATION + "/status.json" |
| 24 | if os.path.exists(status): |
| 25 | with open(status, 'r+') as f: |
| 26 | statusMsg = json.load(f) |
| 27 | if not statusMsg["running"]: |
| 28 | bot.stop_transmission() |
| 29 | speed = current / diff |
| 30 | elapsed_time = round(diff) * 1000 |
| 31 | time_to_completion = round((total - current) / speed) * 1000 |
| 32 | estimated_total_time = elapsed_time + time_to_completion |
| 33 | |
| 34 | elapsed_time = TimeFormatter(milliseconds=elapsed_time) |
| 35 | estimated_total_time = TimeFormatter(milliseconds=estimated_total_time) |
| 36 | |
| 37 | progress = "**[{0}{1}]** `| {2}%`\n\n".format( |
| 38 | ''.join([FINISHED_PROGRESS_STR for i in range(math.floor(percentage / 10))]), |
| 39 | ''.join([UN_FINISHED_PROGRESS_STR for i in range(10 - math.floor(percentage / 10))]), |
| 40 | round(percentage, 2)) |
| 41 | |
| 42 | tmp = progress + "GROSSS: {0} of {1}\n\nSpeed: {2}/s\n\nETA: {3}\n".format( |
| 43 | humanbytes(current), |
| 44 | humanbytes(total), |
| 45 | humanbytes(speed), |
| 46 | estimated_total_time if estimated_total_time != '' else "0 s" |
| 47 | ) |
| 48 | try: |
| 49 | if not message.photo: |
| 50 | await message.edit_text( |
| 51 | text="{}\n {}".format( |
| 52 | ud_type, |
| 53 | tmp |
| 54 | ) |
| 55 | ) |
| 56 | else: |
| 57 | await message.edit_caption( |
| 58 | caption="{}\n {}".format( |
| 59 | ud_type, |
| 60 | tmp |
| 61 | ) |
| 62 | ) |
| 63 | except: |
| 64 | pass |
| 65 | |
| 66 | |
| 67 | def humanbytes(size): |
nothing calls this directly
no test coverage detected