ezKit 2.0.5__tar.gz → 2.0.7__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.
- {ezkit-2.0.5/ezKit.egg-info → ezkit-2.0.7}/PKG-INFO +1 -1
- ezkit-2.0.7/ezKit/stock.py +85 -0
- {ezkit-2.0.5 → ezkit-2.0.7}/ezKit/utils.py +18 -0
- {ezkit-2.0.5 → ezkit-2.0.7/ezKit.egg-info}/PKG-INFO +1 -1
- {ezkit-2.0.5 → ezkit-2.0.7}/ezKit.egg-info/SOURCES.txt +1 -0
- {ezkit-2.0.5 → ezkit-2.0.7}/setup.py +1 -1
- {ezkit-2.0.5 → ezkit-2.0.7}/LICENSE +0 -0
- {ezkit-2.0.5 → ezkit-2.0.7}/MANIFEST.in +0 -0
- {ezkit-2.0.5 → ezkit-2.0.7}/README.md +0 -0
- {ezkit-2.0.5 → ezkit-2.0.7}/ezKit/__init__.py +0 -0
- {ezkit-2.0.5 → ezkit-2.0.7}/ezKit/database.py +0 -0
- {ezkit-2.0.5 → ezkit-2.0.7}/ezKit/http.py +0 -0
- {ezkit-2.0.5 → ezkit-2.0.7}/ezKit/redix.py +0 -0
- {ezkit-2.0.5 → ezkit-2.0.7}/ezKit.egg-info/dependency_links.txt +0 -0
- {ezkit-2.0.5 → ezkit-2.0.7}/ezKit.egg-info/requires.txt +0 -0
- {ezkit-2.0.5 → ezkit-2.0.7}/ezKit.egg-info/top_level.txt +0 -0
- {ezkit-2.0.5 → ezkit-2.0.7}/pyproject.toml +0 -0
- {ezkit-2.0.5 → ezkit-2.0.7}/setup.cfg +0 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""股票"""
|
|
2
|
+
|
|
3
|
+
from copy import deepcopy
|
|
4
|
+
from os import environ
|
|
5
|
+
|
|
6
|
+
from loguru import logger
|
|
7
|
+
|
|
8
|
+
# --------------------------------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
DEBUG = environ.get("DEBUG")
|
|
11
|
+
|
|
12
|
+
# --------------------------------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def coderename(target: str | dict, restore: bool = False) -> str | dict | None:
|
|
16
|
+
"""代码重命名"""
|
|
17
|
+
|
|
18
|
+
# 正向:
|
|
19
|
+
# coderename('000001') => 'sz000001'
|
|
20
|
+
# coderename({'code': '000001', 'name': '平安银行'}) => {'code': 'sz000001', 'name': '平安银行'}
|
|
21
|
+
# 反向:
|
|
22
|
+
# coderename('sz000001', restore=True) => '000001'
|
|
23
|
+
# coderename({'code': 'sz000001', 'name': '平安银行'}) => {'code': '000001', 'name': '平安银行'}
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
|
|
27
|
+
# 初始化
|
|
28
|
+
|
|
29
|
+
code_object: dict = {}
|
|
30
|
+
code_name: str = ""
|
|
31
|
+
|
|
32
|
+
# 判断 target
|
|
33
|
+
|
|
34
|
+
if isinstance(target, str) and target:
|
|
35
|
+
code_name = target
|
|
36
|
+
elif isinstance(target, dict) and target:
|
|
37
|
+
code_object = deepcopy(target)
|
|
38
|
+
code_name = code_object.get("code", "")
|
|
39
|
+
else:
|
|
40
|
+
logger.error("target value or type error")
|
|
41
|
+
return None
|
|
42
|
+
|
|
43
|
+
if not code_name:
|
|
44
|
+
logger.error("code name error")
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
# 是否还原
|
|
48
|
+
|
|
49
|
+
if restore:
|
|
50
|
+
|
|
51
|
+
if len(code_name) != 8 or not code_name.startswith(("sz", "sh")):
|
|
52
|
+
logger.error("code name error")
|
|
53
|
+
return None
|
|
54
|
+
|
|
55
|
+
code_name = code_name[-6:]
|
|
56
|
+
|
|
57
|
+
else:
|
|
58
|
+
|
|
59
|
+
if code_name[0:2] == "00":
|
|
60
|
+
code_name = f"sz{code_name}"
|
|
61
|
+
elif code_name[0:2] == "60":
|
|
62
|
+
code_name = f"sh{code_name}"
|
|
63
|
+
else:
|
|
64
|
+
logger.error("code name error")
|
|
65
|
+
return None
|
|
66
|
+
|
|
67
|
+
# 返回结果
|
|
68
|
+
|
|
69
|
+
if isinstance(target, str):
|
|
70
|
+
return code_name
|
|
71
|
+
|
|
72
|
+
if isinstance(target, dict):
|
|
73
|
+
code_object["code"] = code_name
|
|
74
|
+
return code_object
|
|
75
|
+
|
|
76
|
+
return None
|
|
77
|
+
|
|
78
|
+
except Exception as e:
|
|
79
|
+
|
|
80
|
+
if DEBUG:
|
|
81
|
+
logger.exception(e)
|
|
82
|
+
else:
|
|
83
|
+
logger.error(e)
|
|
84
|
+
|
|
85
|
+
return None
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import re
|
|
4
4
|
import tomllib
|
|
5
5
|
|
|
6
|
+
from datetime import datetime, timezone
|
|
6
7
|
from os import environ
|
|
7
8
|
from typing import Iterable
|
|
8
9
|
|
|
@@ -143,3 +144,20 @@ def check_dict_values_incorrect(
|
|
|
143
144
|
logger.error(e)
|
|
144
145
|
|
|
145
146
|
return False
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
# --------------------------------------------------------------------------------------------------
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def timestamp_to_datetime(timestamp: int | float, tz: timezone = timezone.utc) -> datetime | None:
|
|
153
|
+
"""Unix Timestamp 转换为 Datatime"""
|
|
154
|
+
try:
|
|
155
|
+
if not isinstance(timestamp, (int, float)):
|
|
156
|
+
return None
|
|
157
|
+
return (datetime.fromtimestamp(timestamp, tz=tz)).replace(tzinfo=None)
|
|
158
|
+
except Exception as e:
|
|
159
|
+
if DEBUG:
|
|
160
|
+
logger.exception(e)
|
|
161
|
+
else:
|
|
162
|
+
logger.error(e)
|
|
163
|
+
return None
|
|
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
|