ezKit 2.0.6__tar.gz → 2.0.8__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 2.0.6
3
+ Version: 2.0.8
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -3,8 +3,9 @@
3
3
  import re
4
4
  import tomllib
5
5
 
6
+ from collections.abc import Callable, Iterable
7
+ from datetime import datetime, timezone
6
8
  from os import environ
7
- from typing import Iterable
8
9
 
9
10
  from loguru import logger
10
11
 
@@ -48,6 +49,21 @@ def load_toml_file(file: str) -> dict:
48
49
  # --------------------------------------------------------------------------------------------------
49
50
 
50
51
 
52
+ def map_filter(func: Callable, iterable: Iterable) -> list:
53
+ """对 iterable 执行 func, 并保留为 True 的返回值"""
54
+ try:
55
+ return [x for x in map(func, iterable) if x]
56
+ except Exception as e:
57
+ if DEBUG:
58
+ logger.exception(e)
59
+ else:
60
+ logger.error(e)
61
+ return []
62
+
63
+
64
+ # --------------------------------------------------------------------------------------------------
65
+
66
+
51
67
  def check_dict_values_incorrect(
52
68
  data: dict[str, object],
53
69
  errors: object | Iterable[object] | None = None,
@@ -143,3 +159,20 @@ def check_dict_values_incorrect(
143
159
  logger.error(e)
144
160
 
145
161
  return False
162
+
163
+
164
+ # --------------------------------------------------------------------------------------------------
165
+
166
+
167
+ def timestamp_to_datetime(timestamp: int | float, tz: timezone = timezone.utc) -> datetime | None:
168
+ """Unix Timestamp 转换为 Datatime"""
169
+ try:
170
+ if not isinstance(timestamp, (int, float)):
171
+ return None
172
+ return (datetime.fromtimestamp(timestamp, tz=tz)).replace(tzinfo=None)
173
+ except Exception as e:
174
+ if DEBUG:
175
+ logger.exception(e)
176
+ else:
177
+ logger.error(e)
178
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 2.0.6
3
+ Version: 2.0.8
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -4,7 +4,7 @@ from setuptools import find_packages, setup
4
4
 
5
5
  setup(
6
6
  name="ezKit",
7
- version="2.0.6",
7
+ version="2.0.8",
8
8
  author="septvean",
9
9
  author_email="septvean@gmail.com",
10
10
  description="Easy Kit",
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