From a686eaa53f266c2792bfc6a4b8e51457f6a709f8 Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Thu, 19 Sep 2024 11:25:12 +0800 Subject: [PATCH] feat: new time str format --- api/process.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/api/process.py b/api/process.py index 43b9402..7e5d9cb 100644 --- a/api/process.py +++ b/api/process.py @@ -1,24 +1,20 @@ import time from api.config import GlobalConst as gc -def sec2time(sec): - ret = "" - if sec // 3600 > 0: - ret += f"{sec // 3600}h " - sec = sec - sec // 3600 * 3600 - if sec // 60 > 0: - ret += f"{sec // 60}min " - sec = sec - sec // 60 * 60 - if sec: - ret += f"{sec}s" - if not ret: - ret = "0s" - return ret +def sec2time(sec: int): + h = int(sec / 3600) + m = int(sec % 3600 / 60) + s = int(sec % 60) + if h != 0: + return f'{h}:{m:02}:{s:02}' + if sec != 0: + return f'{m:02}:{s:02}' + return '--:--' -def show_progress(name, start: int, span: int, total: int, _speed: float): +def show_progress(name: str, start: int, span: int, total: int, _speed: float): start_time = time.time() - while int(time.time() - start_time) < int(span // _speed): + while int(time.time() - start_time) < int(span / _speed): current = start + int((time.time() - start_time) * _speed) percent = int(current / total * 100) length = int(percent * 40 // 100)