funcguard 0.1.4__tar.gz → 0.1.5__tar.gz

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.

@@ -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.5
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
@@ -144,18 +144,41 @@ from funcguard import time_log, time_diff
144
144
  # 获取开始时间
145
145
  start_time = time_diff()
146
146
 
147
- # 记录任务开始
148
- time_log("开始处理数据", 0, 100, start_time)
147
+ # 记录任务开始(i从0开始)
148
+ time_log("开始处理数据", 0, 100, 0, start_time)
149
149
 
150
150
  # 模拟处理过程
151
151
  import time
152
152
  for i in range(1, 101):
153
153
  time.sleep(0.1) # 模拟处理时间
154
154
  if i % 20 == 0:
155
- time_log(f"处理进度", i, 100, start_time) # 显示进度和预计完成时间
155
+ time_log(f"处理进度", i, 100, 0, start_time) # 显示进度和预计完成时间
156
156
 
157
157
  # 记录任务完成并打印统计信息
158
- time_log("数据处理完成", 100, 100, start_time)
158
+ time_log("数据处理完成", 100, 100, 0, start_time)
159
+ time_diff(start_time, 100, "cn") # 中文显示统计信息
160
+ ```
161
+
162
+ 或者当i从1开始时:
163
+
164
+ ```python
165
+ from funcguard import time_log, time_diff
166
+
167
+ # 获取开始时间
168
+ start_time = time_diff()
169
+
170
+ # 记录任务开始(i从1开始)
171
+ time_log("开始处理数据", 1, 100, 1, start_time)
172
+
173
+ # 模拟处理过程
174
+ import time
175
+ for i in range(1, 101):
176
+ time.sleep(0.1) # 模拟处理时间
177
+ if i % 20 == 0:
178
+ time_log(f"处理进度", i, 100, 1, start_time) # 显示进度和预计完成时间
179
+
180
+ # 记录任务完成并打印统计信息
181
+ time_log("数据处理完成", 100, 100, 1, start_time)
159
182
  time_diff(start_time, 100, "cn") # 中文显示统计信息
160
183
  ```
161
184
 
@@ -164,6 +187,7 @@ time_diff(start_time, 100, "cn") # 中文显示统计信息
164
187
  - 支持进度显示和预计完成时间计算
165
188
  - 提供中英文双语统计信息
166
189
  - 可显示总耗时、平均耗时等详细统计
190
+ - 支持i从0或从1开始的计数方式
167
191
 
168
192
  ## API文档
169
193
 
@@ -206,12 +230,13 @@ time_diff(start_time, 100, "cn") # 中文显示统计信息
206
230
  - **返回值**: 根据return_type参数返回不同格式的响应数据
207
231
  - **异常**: 当请求失败且重试次数用尽后,抛出相应的异常
208
232
 
209
- #### time_log(message, i=0, max_num=0, s_time=None)
233
+ #### time_log(message, i=0, max_num=0, start_from=0, s_time=None)
210
234
 
211
235
  - **参数**:
212
236
  - `message`: 日志消息
213
- - `i`: 当前进度(从0开始),默认为0
237
+ - `i`: 当前进度,默认为0
214
238
  - `max_num`: 总进度数量,默认为0
239
+ - `start_from`: i是否从0开始,0表示从0开始,1表示从1开始,默认为0
215
240
  - `s_time`: 开始时间,用于计算预计完成时间,默认为None
216
241
  - **返回值**: 无
217
242
  - **功能**: 打印带时间戳的日志信息,支持进度显示和预计完成时间计算
@@ -1,17 +1,3 @@
1
- Metadata-Version: 2.1
2
- Name: funcguard
3
- Version: 0.1.4
4
- Summary: A funcguard for Python.
5
- Home-page: https://github.com/tinycen/funcguard
6
- Author: tinycen
7
- Author-email: sky_ruocen@qq.com
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.10
12
- Description-Content-Type: text/markdown
13
- License-File: LICENSE
14
-
15
1
  # FuncGuard
16
2
 
17
3
  FuncGuard是一个Python库,提供了函数执行超时控制和重试机制的实用工具。
@@ -144,18 +130,41 @@ from funcguard import time_log, time_diff
144
130
  # 获取开始时间
145
131
  start_time = time_diff()
146
132
 
147
- # 记录任务开始
148
- time_log("开始处理数据", 0, 100, start_time)
133
+ # 记录任务开始(i从0开始)
134
+ time_log("开始处理数据", 0, 100, 0, start_time)
135
+
136
+ # 模拟处理过程
137
+ import time
138
+ for i in range(1, 101):
139
+ time.sleep(0.1) # 模拟处理时间
140
+ if i % 20 == 0:
141
+ time_log(f"处理进度", i, 100, 0, start_time) # 显示进度和预计完成时间
142
+
143
+ # 记录任务完成并打印统计信息
144
+ time_log("数据处理完成", 100, 100, 0, start_time)
145
+ time_diff(start_time, 100, "cn") # 中文显示统计信息
146
+ ```
147
+
148
+ 或者当i从1开始时:
149
+
150
+ ```python
151
+ from funcguard import time_log, time_diff
152
+
153
+ # 获取开始时间
154
+ start_time = time_diff()
155
+
156
+ # 记录任务开始(i从1开始)
157
+ time_log("开始处理数据", 1, 100, 1, start_time)
149
158
 
150
159
  # 模拟处理过程
151
160
  import time
152
161
  for i in range(1, 101):
153
162
  time.sleep(0.1) # 模拟处理时间
154
163
  if i % 20 == 0:
155
- time_log(f"处理进度", i, 100, start_time) # 显示进度和预计完成时间
164
+ time_log(f"处理进度", i, 100, 1, start_time) # 显示进度和预计完成时间
156
165
 
157
166
  # 记录任务完成并打印统计信息
158
- time_log("数据处理完成", 100, 100, start_time)
167
+ time_log("数据处理完成", 100, 100, 1, start_time)
159
168
  time_diff(start_time, 100, "cn") # 中文显示统计信息
160
169
  ```
161
170
 
@@ -164,6 +173,7 @@ time_diff(start_time, 100, "cn") # 中文显示统计信息
164
173
  - 支持进度显示和预计完成时间计算
165
174
  - 提供中英文双语统计信息
166
175
  - 可显示总耗时、平均耗时等详细统计
176
+ - 支持i从0或从1开始的计数方式
167
177
 
168
178
  ## API文档
169
179
 
@@ -206,12 +216,13 @@ time_diff(start_time, 100, "cn") # 中文显示统计信息
206
216
  - **返回值**: 根据return_type参数返回不同格式的响应数据
207
217
  - **异常**: 当请求失败且重试次数用尽后,抛出相应的异常
208
218
 
209
- #### time_log(message, i=0, max_num=0, s_time=None)
219
+ #### time_log(message, i=0, max_num=0, start_from=0, s_time=None)
210
220
 
211
221
  - **参数**:
212
222
  - `message`: 日志消息
213
- - `i`: 当前进度(从0开始),默认为0
223
+ - `i`: 当前进度,默认为0
214
224
  - `max_num`: 总进度数量,默认为0
225
+ - `start_from`: i是否从0开始,0表示从0开始,1表示从1开始,默认为0
215
226
  - `s_time`: 开始时间,用于计算预计完成时间,默认为None
216
227
  - **返回值**: 无
217
228
  - **功能**: 打印带时间戳的日志信息,支持进度显示和预计完成时间计算
@@ -247,4 +258,4 @@ time_diff(start_time, 100, "cn") # 中文显示统计信息
247
258
 
248
259
  ## 许可证
249
260
 
250
- MIT License
261
+ MIT License
@@ -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, start_from = 0, s_time = None,) :
72
72
  """
73
73
  打印带时间戳的日志信息,支持进度显示和预计完成时间
74
74
 
75
75
  :param message: 日志消息
76
- :param i: 当前进度(从0开始)
76
+ :param i: 当前进度
77
77
  :param max_num: 总进度数量
78
+ :param start_from: i是否从0开始,0表示从0开始,1表示从1开始
78
79
  :param s_time: 开始时间,用于计算预计完成时间
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,3 +1,17 @@
1
+ Metadata-Version: 2.1
2
+ Name: funcguard
3
+ Version: 0.1.5
4
+ Summary: FuncGuard是一个Python库,提供函数执行超时控制、重试机制、HTTP请求封装和格式化打印工具。
5
+ Home-page: https://github.com/tinycen/funcguard
6
+ Author: tinycen
7
+ Author-email: sky_ruocen@qq.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+
1
15
  # FuncGuard
2
16
 
3
17
  FuncGuard是一个Python库,提供了函数执行超时控制和重试机制的实用工具。
@@ -130,18 +144,41 @@ from funcguard import time_log, time_diff
130
144
  # 获取开始时间
131
145
  start_time = time_diff()
132
146
 
133
- # 记录任务开始
134
- time_log("开始处理数据", 0, 100, start_time)
147
+ # 记录任务开始(i从0开始)
148
+ time_log("开始处理数据", 0, 100, 0, start_time)
149
+
150
+ # 模拟处理过程
151
+ import time
152
+ for i in range(1, 101):
153
+ time.sleep(0.1) # 模拟处理时间
154
+ if i % 20 == 0:
155
+ time_log(f"处理进度", i, 100, 0, start_time) # 显示进度和预计完成时间
156
+
157
+ # 记录任务完成并打印统计信息
158
+ time_log("数据处理完成", 100, 100, 0, start_time)
159
+ time_diff(start_time, 100, "cn") # 中文显示统计信息
160
+ ```
161
+
162
+ 或者当i从1开始时:
163
+
164
+ ```python
165
+ from funcguard import time_log, time_diff
166
+
167
+ # 获取开始时间
168
+ start_time = time_diff()
169
+
170
+ # 记录任务开始(i从1开始)
171
+ time_log("开始处理数据", 1, 100, 1, start_time)
135
172
 
136
173
  # 模拟处理过程
137
174
  import time
138
175
  for i in range(1, 101):
139
176
  time.sleep(0.1) # 模拟处理时间
140
177
  if i % 20 == 0:
141
- time_log(f"处理进度", i, 100, start_time) # 显示进度和预计完成时间
178
+ time_log(f"处理进度", i, 100, 1, start_time) # 显示进度和预计完成时间
142
179
 
143
180
  # 记录任务完成并打印统计信息
144
- time_log("数据处理完成", 100, 100, start_time)
181
+ time_log("数据处理完成", 100, 100, 1, start_time)
145
182
  time_diff(start_time, 100, "cn") # 中文显示统计信息
146
183
  ```
147
184
 
@@ -150,6 +187,7 @@ time_diff(start_time, 100, "cn") # 中文显示统计信息
150
187
  - 支持进度显示和预计完成时间计算
151
188
  - 提供中英文双语统计信息
152
189
  - 可显示总耗时、平均耗时等详细统计
190
+ - 支持i从0或从1开始的计数方式
153
191
 
154
192
  ## API文档
155
193
 
@@ -192,12 +230,13 @@ time_diff(start_time, 100, "cn") # 中文显示统计信息
192
230
  - **返回值**: 根据return_type参数返回不同格式的响应数据
193
231
  - **异常**: 当请求失败且重试次数用尽后,抛出相应的异常
194
232
 
195
- #### time_log(message, i=0, max_num=0, s_time=None)
233
+ #### time_log(message, i=0, max_num=0, start_from=0, s_time=None)
196
234
 
197
235
  - **参数**:
198
236
  - `message`: 日志消息
199
- - `i`: 当前进度(从0开始),默认为0
237
+ - `i`: 当前进度,默认为0
200
238
  - `max_num`: 总进度数量,默认为0
239
+ - `start_from`: i是否从0开始,0表示从0开始,1表示从1开始,默认为0
201
240
  - `s_time`: 开始时间,用于计算预计完成时间,默认为None
202
241
  - **返回值**: 无
203
242
  - **功能**: 打印带时间戳的日志信息,支持进度显示和预计完成时间计算
@@ -233,4 +272,4 @@ time_diff(start_time, 100, "cn") # 中文显示统计信息
233
272
 
234
273
  ## 许可证
235
274
 
236
- MIT License
275
+ MIT License
@@ -9,14 +9,14 @@ except FileNotFoundError:
9
9
 
10
10
  setup(
11
11
  name='funcguard',
12
- version='0.1.4',
12
+ version='0.1.5',
13
13
  packages=find_packages(),
14
14
  install_requires=[
15
15
  'requests',
16
16
  ],
17
17
  author='tinycen',
18
18
  author_email='sky_ruocen@qq.com',
19
- description='A funcguard for Python.',
19
+ description='FuncGuard是一个Python库,提供函数执行超时控制、重试机制、HTTP请求封装和格式化打印工具。',
20
20
  long_description=long_description,
21
21
  long_description_content_type='text/markdown',
22
22
  url='https://github.com/tinycen/funcguard',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes