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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 2.0.5
3
+ Version: 2.0.6
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 2.0.5
3
+ Version: 2.0.6
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -7,6 +7,7 @@ ezKit/__init__.py
7
7
  ezKit/database.py
8
8
  ezKit/http.py
9
9
  ezKit/redix.py
10
+ ezKit/stock.py
10
11
  ezKit/utils.py
11
12
  ezKit.egg-info/PKG-INFO
12
13
  ezKit.egg-info/SOURCES.txt
@@ -4,7 +4,7 @@ from setuptools import find_packages, setup
4
4
 
5
5
  setup(
6
6
  name="ezKit",
7
- version="2.0.5",
7
+ version="2.0.6",
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