ezKit 2.0.5__tar.gz → 2.0.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.
- {ezkit-2.0.5/ezKit.egg-info → ezkit-2.0.6}/PKG-INFO +1 -1
- ezkit-2.0.6/ezKit/stock.py +85 -0
- {ezkit-2.0.5 → ezkit-2.0.6/ezKit.egg-info}/PKG-INFO +1 -1
- {ezkit-2.0.5 → ezkit-2.0.6}/ezKit.egg-info/SOURCES.txt +1 -0
- {ezkit-2.0.5 → ezkit-2.0.6}/setup.py +1 -1
- {ezkit-2.0.5 → ezkit-2.0.6}/LICENSE +0 -0
- {ezkit-2.0.5 → ezkit-2.0.6}/MANIFEST.in +0 -0
- {ezkit-2.0.5 → ezkit-2.0.6}/README.md +0 -0
- {ezkit-2.0.5 → ezkit-2.0.6}/ezKit/__init__.py +0 -0
- {ezkit-2.0.5 → ezkit-2.0.6}/ezKit/database.py +0 -0
- {ezkit-2.0.5 → ezkit-2.0.6}/ezKit/http.py +0 -0
- {ezkit-2.0.5 → ezkit-2.0.6}/ezKit/redix.py +0 -0
- {ezkit-2.0.5 → ezkit-2.0.6}/ezKit/utils.py +0 -0
- {ezkit-2.0.5 → ezkit-2.0.6}/ezKit.egg-info/dependency_links.txt +0 -0
- {ezkit-2.0.5 → ezkit-2.0.6}/ezKit.egg-info/requires.txt +0 -0
- {ezkit-2.0.5 → ezkit-2.0.6}/ezKit.egg-info/top_level.txt +0 -0
- {ezkit-2.0.5 → ezkit-2.0.6}/pyproject.toml +0 -0
- {ezkit-2.0.5 → ezkit-2.0.6}/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
|
|
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
|