funcguard 0.1.4__tar.gz → 0.1.6__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.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
@@ -144,26 +144,42 @@ 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, start_time, 0)
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, start_time, 0) # 显示进度和预计完成时间
156
156
 
157
157
  # 记录任务完成并打印统计信息
158
- time_log("数据处理完成", 100, 100, start_time)
159
158
  time_diff(start_time, 100, "cn") # 中文显示统计信息
160
159
  ```
161
160
 
161
+ 或者当i从1开始时:
162
+
163
+ ```python
164
+
165
+ # 记录任务开始(i从1开始)
166
+ time_log("开始处理数据", 1, 100, start_time, 1)
167
+
168
+ # 模拟处理过程
169
+ import time
170
+ for i in range(1, 101):
171
+ time.sleep(0.1) # 模拟处理时间
172
+ if i % 20 == 0:
173
+ time_log(f"处理进度", i, 100, start_time, 1) # 显示进度和预计完成时间
174
+
175
+ ```
176
+
162
177
  时间日志功能特点:
163
178
  - 自动显示北京时间(UTC+8)
164
179
  - 支持进度显示和预计完成时间计算
165
180
  - 提供中英文双语统计信息
166
181
  - 可显示总耗时、平均耗时等详细统计
182
+ - 支持i从0或从1开始的计数方式
167
183
 
168
184
  ## API文档
169
185
 
@@ -206,13 +222,14 @@ time_diff(start_time, 100, "cn") # 中文显示统计信息
206
222
  - **返回值**: 根据return_type参数返回不同格式的响应数据
207
223
  - **异常**: 当请求失败且重试次数用尽后,抛出相应的异常
208
224
 
209
- #### time_log(message, i=0, max_num=0, s_time=None)
225
+ #### time_log(message, i=0, max_num=0, s_time=None, start_from=0)
210
226
 
211
227
  - **参数**:
212
228
  - `message`: 日志消息
213
- - `i`: 当前进度(从0开始),默认为0
229
+ - `i`: 当前进度,默认为0
214
230
  - `max_num`: 总进度数量,默认为0
215
231
  - `s_time`: 开始时间,用于计算预计完成时间,默认为None
232
+ - `start_from`: i是否从0开始,0表示从0开始,1表示从1开始,默认为0
216
233
  - **返回值**: 无
217
234
  - **功能**: 打印带时间戳的日志信息,支持进度显示和预计完成时间计算
218
235
 
@@ -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,26 +130,42 @@ 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, start_time, 0)
149
135
 
150
136
  # 模拟处理过程
151
137
  import time
152
138
  for i in range(1, 101):
153
139
  time.sleep(0.1) # 模拟处理时间
154
140
  if i % 20 == 0:
155
- time_log(f"处理进度", i, 100, start_time) # 显示进度和预计完成时间
141
+ time_log(f"处理进度", i, 100, start_time, 0) # 显示进度和预计完成时间
156
142
 
157
143
  # 记录任务完成并打印统计信息
158
- time_log("数据处理完成", 100, 100, start_time)
159
144
  time_diff(start_time, 100, "cn") # 中文显示统计信息
160
145
  ```
161
146
 
147
+ 或者当i从1开始时:
148
+
149
+ ```python
150
+
151
+ # 记录任务开始(i从1开始)
152
+ time_log("开始处理数据", 1, 100, start_time, 1)
153
+
154
+ # 模拟处理过程
155
+ import time
156
+ for i in range(1, 101):
157
+ time.sleep(0.1) # 模拟处理时间
158
+ if i % 20 == 0:
159
+ time_log(f"处理进度", i, 100, start_time, 1) # 显示进度和预计完成时间
160
+
161
+ ```
162
+
162
163
  时间日志功能特点:
163
164
  - 自动显示北京时间(UTC+8)
164
165
  - 支持进度显示和预计完成时间计算
165
166
  - 提供中英文双语统计信息
166
167
  - 可显示总耗时、平均耗时等详细统计
168
+ - 支持i从0或从1开始的计数方式
167
169
 
168
170
  ## API文档
169
171
 
@@ -206,13 +208,14 @@ time_diff(start_time, 100, "cn") # 中文显示统计信息
206
208
  - **返回值**: 根据return_type参数返回不同格式的响应数据
207
209
  - **异常**: 当请求失败且重试次数用尽后,抛出相应的异常
208
210
 
209
- #### time_log(message, i=0, max_num=0, s_time=None)
211
+ #### time_log(message, i=0, max_num=0, s_time=None, start_from=0)
210
212
 
211
213
  - **参数**:
212
214
  - `message`: 日志消息
213
- - `i`: 当前进度(从0开始),默认为0
215
+ - `i`: 当前进度,默认为0
214
216
  - `max_num`: 总进度数量,默认为0
215
217
  - `s_time`: 开始时间,用于计算预计完成时间,默认为None
218
+ - `start_from`: i是否从0开始,0表示从0开始,1表示从1开始,默认为0
216
219
  - **返回值**: 无
217
220
  - **功能**: 打印带时间戳的日志信息,支持进度显示和预计完成时间计算
218
221
 
@@ -247,4 +250,4 @@ time_diff(start_time, 100, "cn") # 中文显示统计信息
247
250
 
248
251
  ## 许可证
249
252
 
250
- MIT License
253
+ 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, 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,3 +1,17 @@
1
+ Metadata-Version: 2.1
2
+ Name: funcguard
3
+ Version: 0.1.6
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,26 +144,42 @@ 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, start_time, 0)
135
149
 
136
150
  # 模拟处理过程
137
151
  import time
138
152
  for i in range(1, 101):
139
153
  time.sleep(0.1) # 模拟处理时间
140
154
  if i % 20 == 0:
141
- time_log(f"处理进度", i, 100, start_time) # 显示进度和预计完成时间
155
+ time_log(f"处理进度", i, 100, start_time, 0) # 显示进度和预计完成时间
142
156
 
143
157
  # 记录任务完成并打印统计信息
144
- time_log("数据处理完成", 100, 100, start_time)
145
158
  time_diff(start_time, 100, "cn") # 中文显示统计信息
146
159
  ```
147
160
 
161
+ 或者当i从1开始时:
162
+
163
+ ```python
164
+
165
+ # 记录任务开始(i从1开始)
166
+ time_log("开始处理数据", 1, 100, start_time, 1)
167
+
168
+ # 模拟处理过程
169
+ import time
170
+ for i in range(1, 101):
171
+ time.sleep(0.1) # 模拟处理时间
172
+ if i % 20 == 0:
173
+ time_log(f"处理进度", i, 100, start_time, 1) # 显示进度和预计完成时间
174
+
175
+ ```
176
+
148
177
  时间日志功能特点:
149
178
  - 自动显示北京时间(UTC+8)
150
179
  - 支持进度显示和预计完成时间计算
151
180
  - 提供中英文双语统计信息
152
181
  - 可显示总耗时、平均耗时等详细统计
182
+ - 支持i从0或从1开始的计数方式
153
183
 
154
184
  ## API文档
155
185
 
@@ -192,13 +222,14 @@ time_diff(start_time, 100, "cn") # 中文显示统计信息
192
222
  - **返回值**: 根据return_type参数返回不同格式的响应数据
193
223
  - **异常**: 当请求失败且重试次数用尽后,抛出相应的异常
194
224
 
195
- #### time_log(message, i=0, max_num=0, s_time=None)
225
+ #### time_log(message, i=0, max_num=0, s_time=None, start_from=0)
196
226
 
197
227
  - **参数**:
198
228
  - `message`: 日志消息
199
- - `i`: 当前进度(从0开始),默认为0
229
+ - `i`: 当前进度,默认为0
200
230
  - `max_num`: 总进度数量,默认为0
201
231
  - `s_time`: 开始时间,用于计算预计完成时间,默认为None
232
+ - `start_from`: i是否从0开始,0表示从0开始,1表示从1开始,默认为0
202
233
  - **返回值**: 无
203
234
  - **功能**: 打印带时间戳的日志信息,支持进度显示和预计完成时间计算
204
235
 
@@ -233,4 +264,4 @@ time_diff(start_time, 100, "cn") # 中文显示统计信息
233
264
 
234
265
  ## 许可证
235
266
 
236
- MIT License
267
+ 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.6',
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