funcguard 0.1.4__py3-none-any.whl → 0.1.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of funcguard might be problematic. Click here for more details.

funcguard/tools.py CHANGED
@@ -68,30 +68,31 @@ def send_request(
68
68
 
69
69
 
70
70
  # 打印时间
71
- def time_log(message, i = 0, max_num = 0, s_time = None) :
71
+ def time_log(message, i = 0, max_num = 0, s_time = None, start_from = 0 ) :
72
72
  """
73
73
  打印带时间戳的日志信息,支持进度显示和预计完成时间
74
74
 
75
75
  :param message: 日志消息
76
- :param i: 当前进度(从0开始)
76
+ :param i: 当前进度
77
77
  :param max_num: 总进度数量
78
78
  :param s_time: 开始时间,用于计算预计完成时间
79
+ :param start_from: i是否从0开始,0表示从0开始,1表示从1开始
79
80
  :return: None
80
81
  """
81
82
  now = datetime.now( timezone( timedelta( hours = 8 ) ) )
82
83
  time_log = "{:02d}:{:02d}:{:02d}".format( now.hour, now.minute, now.second )
83
- if i < 2 :
84
+ if i < 2 or max_num < 2 :
84
85
  print( time_log + " " + message )
86
+
85
87
  else :
86
- if max_num == 0 :
87
- text = "{}".format( i )
88
- else :
89
- text = "{}/{}".format( i, max_num )
88
+ # 根据start_from参数计算实际处理的项目数
89
+ process_item = i + 1 if start_from == 0 else i
90
+ text = "{}/{}".format( process_item, max_num )
90
91
  # 检查是否应该显示预计完成时间和剩余时间
91
- if i % 10 == 0 and s_time is not None and i < max_num :
92
+ if process_item % 10 == 0 and s_time is not None and process_item < max_num :
92
93
  duration = now - s_time
93
- ev_duration = duration / i # 每项平均耗时
94
- remaining_items = max_num - i
94
+ ev_duration = duration / process_item # 每项平均耗时
95
+ remaining_items = max_num - process_item
95
96
  time_left = ev_duration * remaining_items
96
97
  end_time = now + time_left
97
98
  end_time_str = end_time.strftime( "%Y-%m-%d %H:%M" )
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: funcguard
3
- Version: 0.1.4
4
- Summary: A funcguard for Python.
3
+ Version: 0.1.6
4
+ Summary: FuncGuard是一个Python库,提供函数执行超时控制、重试机制、HTTP请求封装和格式化打印工具。
5
5
  Home-page: https://github.com/tinycen/funcguard
6
6
  Author: tinycen
7
7
  Author-email: sky_ruocen@qq.com
@@ -145,26 +145,42 @@ from funcguard import time_log, time_diff
145
145
  # 获取开始时间
146
146
  start_time = time_diff()
147
147
 
148
- # 记录任务开始
149
- time_log("开始处理数据", 0, 100, start_time)
148
+ # 记录任务开始(i从0开始)
149
+ time_log("开始处理数据", 0, 100, start_time, 0)
150
150
 
151
151
  # 模拟处理过程
152
152
  import time
153
153
  for i in range(1, 101):
154
154
  time.sleep(0.1) # 模拟处理时间
155
155
  if i % 20 == 0:
156
- time_log(f"处理进度", i, 100, start_time) # 显示进度和预计完成时间
156
+ time_log(f"处理进度", i, 100, start_time, 0) # 显示进度和预计完成时间
157
157
 
158
158
  # 记录任务完成并打印统计信息
159
- time_log("数据处理完成", 100, 100, start_time)
160
159
  time_diff(start_time, 100, "cn") # 中文显示统计信息
161
160
  ```
162
161
 
162
+ 或者当i从1开始时:
163
+
164
+ ```python
165
+
166
+ # 记录任务开始(i从1开始)
167
+ time_log("开始处理数据", 1, 100, start_time, 1)
168
+
169
+ # 模拟处理过程
170
+ import time
171
+ for i in range(1, 101):
172
+ time.sleep(0.1) # 模拟处理时间
173
+ if i % 20 == 0:
174
+ time_log(f"处理进度", i, 100, start_time, 1) # 显示进度和预计完成时间
175
+
176
+ ```
177
+
163
178
  时间日志功能特点:
164
179
  - 自动显示北京时间(UTC+8)
165
180
  - 支持进度显示和预计完成时间计算
166
181
  - 提供中英文双语统计信息
167
182
  - 可显示总耗时、平均耗时等详细统计
183
+ - 支持i从0或从1开始的计数方式
168
184
 
169
185
  ## API文档
170
186
 
@@ -207,13 +223,14 @@ time_diff(start_time, 100, "cn") # 中文显示统计信息
207
223
  - **返回值**: 根据return_type参数返回不同格式的响应数据
208
224
  - **异常**: 当请求失败且重试次数用尽后,抛出相应的异常
209
225
 
210
- #### time_log(message, i=0, max_num=0, s_time=None)
226
+ #### time_log(message, i=0, max_num=0, s_time=None, start_from=0)
211
227
 
212
228
  - **参数**:
213
229
  - `message`: 日志消息
214
- - `i`: 当前进度(从0开始),默认为0
230
+ - `i`: 当前进度,默认为0
215
231
  - `max_num`: 总进度数量,默认为0
216
232
  - `s_time`: 开始时间,用于计算预计完成时间,默认为None
233
+ - `start_from`: i是否从0开始,0表示从0开始,1表示从1开始,默认为0
217
234
  - **返回值**: 无
218
235
  - **功能**: 打印带时间戳的日志信息,支持进度显示和预计完成时间计算
219
236
 
@@ -1,13 +1,13 @@
1
1
  funcguard/__init__.py,sha256=iyM7STP-KSxUn7PUaBWEQcZus2XskiGTTweI4qjoETE,342
2
2
  funcguard/core.py,sha256=-rFRkE-udxM0wxlcv9Qi_yIQBRdVrGgwza-LYQsVRLg,3632
3
3
  funcguard/printer.py,sha256=c93x6Z-6a7nnead_Rk_f0Xe23kdVdSj4qaxsuBMKfd0,958
4
- funcguard/tools.py,sha256=S7t46KurOedvVKCVoFLW_CoDvLSC__lfVLUYBse5ABM,5433
4
+ funcguard/tools.py,sha256=YIrr1qFWEU61R5Plk5UXGAyp9yGJrm28-POhNsttZsg,5623
5
5
  tests/__init__.py,sha256=VW6FdWdSC_PL3zEtpkRQfUMf6yVD2OfwtSds82jawTs,26
6
6
  tests/run_test.py,sha256=-SLdUV7gDifLxuCCAlU8qLxYMx6KpK4cxfG4UYfUIgA,1005
7
7
  tests/test_core.py,sha256=aZNbQK4eTnnkCI4c2txYZNTcYIUhSJvII5Dvn0vNJKo,3732
8
8
  tests/test_tools.py,sha256=g9dK-WW1s5SIobscRuelufBfPrSgNLZU8d1AJteBpd0,5609
9
- funcguard-0.1.4.dist-info/LICENSE,sha256=jgOquECfjiXp5xXQ2zuzItDr4XDBLan-bIzIXl1lS4Y,1064
10
- funcguard-0.1.4.dist-info/METADATA,sha256=ayz3u_YGwUqH3ziy-awhbPMjWgFdPWYCxSQmTZJF-HI,7175
11
- funcguard-0.1.4.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
12
- funcguard-0.1.4.dist-info/top_level.txt,sha256=7wL9mWT062DttKNO7Wi1wYWTZilR2AOPRO0rE3gvtB4,16
13
- funcguard-0.1.4.dist-info/RECORD,,
9
+ funcguard-0.1.6.dist-info/LICENSE,sha256=jgOquECfjiXp5xXQ2zuzItDr4XDBLan-bIzIXl1lS4Y,1064
10
+ funcguard-0.1.6.dist-info/METADATA,sha256=sT6MGwKqp1CyIaKpsmOdzWC7eg-16FOsUMG4XF3t4bM,7723
11
+ funcguard-0.1.6.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
12
+ funcguard-0.1.6.dist-info/top_level.txt,sha256=7wL9mWT062DttKNO7Wi1wYWTZilR2AOPRO0rE3gvtB4,16
13
+ funcguard-0.1.6.dist-info/RECORD,,