funcguard 0.2.53__tar.gz → 0.2.54__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.
- {funcguard-0.2.53 → funcguard-0.2.54}/PKG-INFO +2 -3
- {funcguard-0.2.53 → funcguard-0.2.54}/README.md +1 -2
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/__init__.py +1 -2
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/time_utils.py +34 -33
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard.egg-info/PKG-INFO +2 -3
- {funcguard-0.2.53 → funcguard-0.2.54}/setup.py +1 -1
- {funcguard-0.2.53 → funcguard-0.2.54}/LICENSE +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/calculate.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/core.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/data_models/__init__.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/data_models/request_models.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/ip_utils.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/log_utils.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/pd_utils/__init__.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/pd_utils/convert_utils.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/pd_utils/date_utils.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/pd_utils/fill_round.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/pd_utils/filter.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/pd_utils/json_utils/__init__.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/pd_utils/json_utils/json_parser.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/pd_utils/statistics/__init__.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/pd_utils/statistics/agg_utils.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/pd_utils/statistics/count_utils.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/pd_utils/statistics/df_statistics.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/pd_utils/statistics/mask_utils.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/printer.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard/tools.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard.egg-info/SOURCES.txt +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard.egg-info/dependency_links.txt +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard.egg-info/not-zip-safe +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard.egg-info/requires.txt +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/funcguard.egg-info/top_level.txt +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/setup.cfg +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/tests/__init__.py +0 -0
- {funcguard-0.2.53 → funcguard-0.2.54}/tests/test_pd_filter_empty.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: funcguard
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.54
|
|
4
4
|
Summary: FuncGuard是一个Python库,提供函数执行超时控制、重试机制、HTTP请求封装和格式化打印工具。
|
|
5
5
|
Home-page: https://github.com/tinycen/funcguard
|
|
6
6
|
Author: tinycen
|
|
@@ -589,8 +589,7 @@ print(f"当前价格: {current_price}, 变化: {price_change}") # 输出: 当
|
|
|
589
589
|
| `time_diff` | 耗时统计和计算 | [查看](docs/time_utils.md#time_diff) |
|
|
590
590
|
| `time_monitor` | 函数执行时间监控和警告 | [查看](docs/time_utils.md#time_monitor) |
|
|
591
591
|
| `time_wait` | 时间等待(带倒计时显示) | [查看](docs/time_utils.md#time_wait) |
|
|
592
|
-
| `get_now` |
|
|
593
|
-
| `generate_timestamp` | 生成时间戳 | - |
|
|
592
|
+
| `get_now` | 获取当前时间(支持多种格式输出) | - |
|
|
594
593
|
| `cal_date_diff` | 计算日期差异 | - |
|
|
595
594
|
|
|
596
595
|
### 打印工具
|
|
@@ -557,8 +557,7 @@ print(f"当前价格: {current_price}, 变化: {price_change}") # 输出: 当
|
|
|
557
557
|
| `time_diff` | 耗时统计和计算 | [查看](docs/time_utils.md#time_diff) |
|
|
558
558
|
| `time_monitor` | 函数执行时间监控和警告 | [查看](docs/time_utils.md#time_monitor) |
|
|
559
559
|
| `time_wait` | 时间等待(带倒计时显示) | [查看](docs/time_utils.md#time_wait) |
|
|
560
|
-
| `get_now` |
|
|
561
|
-
| `generate_timestamp` | 生成时间戳 | - |
|
|
560
|
+
| `get_now` | 获取当前时间(支持多种格式输出) | - |
|
|
562
561
|
| `cal_date_diff` | 计算日期差异 | - |
|
|
563
562
|
|
|
564
563
|
### 打印工具
|
|
@@ -2,7 +2,7 @@ from .core import timeout_handler, retry_function, ask_select
|
|
|
2
2
|
from .tools import send_request, curl_cffi_request, check_url_valid, encode_basic_auth, md5_hash
|
|
3
3
|
from .time_utils import (
|
|
4
4
|
time_log, time_diff, time_monitor, time_wait, color_logger,
|
|
5
|
-
get_now,
|
|
5
|
+
get_now, cal_date_diff
|
|
6
6
|
)
|
|
7
7
|
|
|
8
8
|
from .printer import print_block, print_line, print_title, print_progress
|
|
@@ -68,7 +68,6 @@ __all__ = [
|
|
|
68
68
|
"setup_logger",
|
|
69
69
|
"color_logger",
|
|
70
70
|
"get_now",
|
|
71
|
-
"generate_timestamp",
|
|
72
71
|
"cal_date_diff",
|
|
73
72
|
|
|
74
73
|
# 打印工具
|
|
@@ -177,61 +177,62 @@ def time_monitor(warning_threshold=None, print_mode=2, func=None, *args, **kwarg
|
|
|
177
177
|
|
|
178
178
|
|
|
179
179
|
# 获取当前的时间
|
|
180
|
-
def get_now( from_timezone = "local", remove_tzinfo = True ):
|
|
180
|
+
def get_now( from_timezone = "local", remove_tzinfo = True, fmt = None ):
|
|
181
|
+
"""
|
|
182
|
+
获取当前时间,支持多种时区和输出格式。
|
|
183
|
+
|
|
184
|
+
:param from_timezone: 时区选择:
|
|
185
|
+
- "local": 本地时间(tz-naive,不含时区信息)。
|
|
186
|
+
- "utc": UTC时间(tz-aware,包含 UTC 时区信息)。
|
|
187
|
+
- "bj": 北京时间(tz-aware,包含 UTC+8 时区信息)。
|
|
188
|
+
|
|
189
|
+
naive vs aware 的区别:
|
|
190
|
+
- naive(无时区信息):仅表示一个日期和时间,不知道自己处于哪个时区,其含义取决于运行环境。
|
|
191
|
+
- aware(有时区信息):包含时区信息,能够准确定位自己在绝对时间轴上的位置。
|
|
192
|
+
- naive 和 aware 不能直接进行比较/计算,因为 naive 对象没有时区信息,无法确定其在时间轴上的具体位置。
|
|
193
|
+
|
|
194
|
+
:param remove_tzinfo: 是否移除时区信息,默认为 True(仅 fmt=None 时生效,影响返回的 datetime 对象)
|
|
195
|
+
:param fmt: 输出格式,默认为 None(返回 datetime 对象):
|
|
196
|
+
- None: 返回 datetime 对象
|
|
197
|
+
- "millis": 返回毫秒级时间戳(int)
|
|
198
|
+
- "iso": 返回 ISO 8601 格式字符串,例如 2024-03-15T14:00:00;当 from_timezone="utc" 时自动追加 Z 后缀(Z = Zulu time = UTC+0)
|
|
199
|
+
- "str": 返回普通字符串,格式为 %Y-%m-%d %H:%M:%S
|
|
200
|
+
:return: datetime 对象 | int(毫秒时间戳) | str(格式化字符串)
|
|
201
|
+
"""
|
|
181
202
|
if from_timezone == "local" :
|
|
182
203
|
now_time = datetime.now() # 获取当前本地时间 (tz-naive) ,不包含时区信息
|
|
183
204
|
|
|
184
205
|
elif from_timezone == "utc" :
|
|
185
206
|
now_time = datetime.now( timezone.utc ) # 获取当前UTC时间 (tz-aware) ,包含时区信息
|
|
186
207
|
|
|
187
|
-
elif from_timezone == "
|
|
208
|
+
elif from_timezone == "bj" : # 固定北京时间 (tz-aware) ,包含时区信息
|
|
188
209
|
now_time = datetime.now( timezone( timedelta( hours = 8 ) ) )
|
|
189
210
|
|
|
190
|
-
else :
|
|
191
|
-
raise ValueError( "Invalid timezone , must be 'local' , 'utc' , '
|
|
192
|
-
|
|
193
|
-
if remove_tzinfo:
|
|
194
|
-
return now_time.replace( tzinfo = None )
|
|
195
|
-
|
|
196
|
-
return now_time
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
# 获取时间戳
|
|
200
|
-
def generate_timestamp( from_timezone = "local", fmt = "millis", utc_z = False ) :
|
|
201
|
-
"""
|
|
202
|
-
获取当前时间戳或格式化时间字符串
|
|
203
|
-
|
|
204
|
-
:param from_timezone: 时区选择,决定返回的时间对象类型:
|
|
205
|
-
- "local": 返回本地时间的 naive 对象(不含时区信息)。
|
|
206
|
-
- "utc": 返回 UTC 时间的 aware 对象(包含 UTC 时区信息)。
|
|
207
|
-
- "beijing": 返回北京时间的 aware 对象(包含 UTC+8 时区信息)。
|
|
208
|
-
|
|
209
|
-
naive vs aware 的区别:
|
|
210
|
-
- naive (无时区信息):不包含时区信息的对象。它仅表示一个日期和时间,但不知道自己处于哪个时区。其含义取决于运行环境。
|
|
211
|
-
- aware (有时区信息):包含时区信息的对象。它能够准确地定位自己在绝对时间轴上的位置。
|
|
212
|
-
- naive 和 aware 不能直接进行比较/计算,因为 naive 对象没有时区信息,无法确定其在时间轴上的具体位置。
|
|
211
|
+
else :
|
|
212
|
+
raise ValueError( "Invalid timezone , must be 'local' , 'utc' , 'bj' " )
|
|
213
213
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
214
|
+
# 未指定 fmt 时,返回 datetime 对象
|
|
215
|
+
if fmt is None :
|
|
216
|
+
if remove_tzinfo :
|
|
217
|
+
return now_time.replace( tzinfo = None )
|
|
218
|
+
return now_time
|
|
218
219
|
|
|
219
|
-
# 格式化为ISO 8601
|
|
220
|
+
# 格式化为 ISO 8601 标准格式(UTC 时区自动追加 Z 后缀)
|
|
220
221
|
if fmt == "iso" :
|
|
221
|
-
if from_timezone == "utc"
|
|
222
|
+
if from_timezone == "utc" :
|
|
222
223
|
return now_time.strftime( '%Y-%m-%dT%H:%M:%SZ' )
|
|
223
|
-
|
|
224
224
|
return now_time.strftime( '%Y-%m-%dT%H:%M:%S' )
|
|
225
225
|
|
|
226
226
|
# 转换为毫秒级时间戳
|
|
227
227
|
elif fmt == "millis" :
|
|
228
228
|
return int( now_time.timestamp() * 1000 )
|
|
229
229
|
|
|
230
|
+
# 格式化为普通字符串
|
|
230
231
|
elif fmt == "str" :
|
|
231
232
|
return now_time.strftime( '%Y-%m-%d %H:%M:%S' )
|
|
232
233
|
|
|
233
234
|
else :
|
|
234
|
-
raise ValueError( "Invalid fmt , must be 'millis' , 'iso' or 'str'" )
|
|
235
|
+
raise ValueError( "Invalid fmt , must be None , 'millis' , 'iso' or 'str'" )
|
|
235
236
|
|
|
236
237
|
|
|
237
238
|
# 计算日期差值
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: funcguard
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.54
|
|
4
4
|
Summary: FuncGuard是一个Python库,提供函数执行超时控制、重试机制、HTTP请求封装和格式化打印工具。
|
|
5
5
|
Home-page: https://github.com/tinycen/funcguard
|
|
6
6
|
Author: tinycen
|
|
@@ -589,8 +589,7 @@ print(f"当前价格: {current_price}, 变化: {price_change}") # 输出: 当
|
|
|
589
589
|
| `time_diff` | 耗时统计和计算 | [查看](docs/time_utils.md#time_diff) |
|
|
590
590
|
| `time_monitor` | 函数执行时间监控和警告 | [查看](docs/time_utils.md#time_monitor) |
|
|
591
591
|
| `time_wait` | 时间等待(带倒计时显示) | [查看](docs/time_utils.md#time_wait) |
|
|
592
|
-
| `get_now` |
|
|
593
|
-
| `generate_timestamp` | 生成时间戳 | - |
|
|
592
|
+
| `get_now` | 获取当前时间(支持多种格式输出) | - |
|
|
594
593
|
| `cal_date_diff` | 计算日期差异 | - |
|
|
595
594
|
|
|
596
595
|
### 打印工具
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|