ezKit 1.8.1__tar.gz → 1.8.3__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-1.8.1/ezKit.egg-info → ezkit-1.8.3}/PKG-INFO +1 -1
- {ezkit-1.8.1 → ezkit-1.8.3}/ezKit/cipher.py +5 -6
- ezkit-1.8.3/ezKit/cls.py +170 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/ezKit/database.py +7 -8
- {ezkit-1.8.1 → ezkit-1.8.3}/ezKit/http.py +1 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/ezKit/qywx.py +21 -18
- ezkit-1.8.3/ezKit/stock.py +60 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/ezKit/xftp.py +2 -3
- {ezkit-1.8.1 → ezkit-1.8.3/ezKit.egg-info}/PKG-INFO +1 -1
- {ezkit-1.8.1 → ezkit-1.8.3}/ezKit.egg-info/SOURCES.txt +2 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/setup.py +1 -1
- {ezkit-1.8.1 → ezkit-1.8.3}/LICENSE +0 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/MANIFEST.in +0 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/README.md +0 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/ezKit/__init__.py +0 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/ezKit/bottle.py +0 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/ezKit/bottle_extensions.py +0 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/ezKit/mongo.py +0 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/ezKit/redis.py +0 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/ezKit/sendemail.py +0 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/ezKit/token.py +0 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/ezKit/utils.py +0 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/ezKit.egg-info/dependency_links.txt +0 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/ezKit.egg-info/requires.txt +0 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/ezKit.egg-info/top_level.txt +0 -0
- {ezkit-1.8.1 → ezkit-1.8.3}/setup.cfg +0 -0
@@ -1,9 +1,8 @@
|
|
1
|
-
"""
|
2
|
-
https://docs.python.org/3.10/library/hashlib.html
|
3
|
-
https://www.pycrypto.org/
|
4
|
-
https://stackoverflow.com/a/21928790
|
5
|
-
pip install pycryptodome
|
6
|
-
"""
|
1
|
+
"""Cipher"""
|
2
|
+
# https://docs.python.org/3.10/library/hashlib.html
|
3
|
+
# https://www.pycrypto.org/
|
4
|
+
# https://stackoverflow.com/a/21928790
|
5
|
+
# pip install pycryptodome
|
7
6
|
import base64
|
8
7
|
import hashlib
|
9
8
|
|
ezkit-1.8.3/ezKit/cls.py
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
"""财联社数据"""
|
2
|
+
import re
|
3
|
+
|
4
|
+
import pandas as pd
|
5
|
+
import requests
|
6
|
+
from loguru import logger
|
7
|
+
|
8
|
+
from . import stock, utils
|
9
|
+
|
10
|
+
|
11
|
+
def up_down_analysis(
|
12
|
+
target: str = "up_pool",
|
13
|
+
df: bool = False
|
14
|
+
) -> list | pd.DataFrame | None:
|
15
|
+
"""涨停跌停数据"""
|
16
|
+
|
17
|
+
if not utils.v_true(target, str):
|
18
|
+
logger.error(f"error type: {target}")
|
19
|
+
return None
|
20
|
+
|
21
|
+
info: str = "获取涨停池股票"
|
22
|
+
match True:
|
23
|
+
case True if target == "up_pool":
|
24
|
+
info = "获取涨停池股票"
|
25
|
+
case True if target == "continuous_up_pool":
|
26
|
+
info = "获取连板池股票"
|
27
|
+
case True if target == "up_open_pool":
|
28
|
+
info = "获取炸板池股票"
|
29
|
+
case True if target == "down_pool":
|
30
|
+
info = "获取跌停池股票"
|
31
|
+
case _:
|
32
|
+
pass
|
33
|
+
|
34
|
+
try:
|
35
|
+
logger.info(f"{info} ......")
|
36
|
+
|
37
|
+
user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
|
38
|
+
headers = {"User-Agent": user_agent}
|
39
|
+
|
40
|
+
# 涨停池: https://x-quote.cls.cn/quote/index/up_down_analysis?rever=1&way=last_px&type=up_pool
|
41
|
+
# 连板池: https://x-quote.cls.cn/quote/index/up_down_analysis?rever=1&way=last_px&type=continuous_up_pool
|
42
|
+
# 炸板池: https://x-quote.cls.cn/quote/index/up_down_analysis?rever=1&way=last_px&type=up_open_pool
|
43
|
+
# 跌停池: https://x-quote.cls.cn/quote/index/up_down_analysis?rever=1&way=last_px&type=down_pool
|
44
|
+
api = f"https://x-quote.cls.cn/quote/index/up_down_analysis?rever=1&way=last_px&type={target}"
|
45
|
+
|
46
|
+
response = requests.get(api, headers=headers, timeout=10)
|
47
|
+
|
48
|
+
response_dict: dict = response.json()
|
49
|
+
|
50
|
+
result: list = []
|
51
|
+
|
52
|
+
for i in response_dict["data"]:
|
53
|
+
|
54
|
+
# if re.match(r"^(sz00|sh60)", i["secu_code"]):
|
55
|
+
# print(i["secu_code"])
|
56
|
+
|
57
|
+
# if re.search(r"ST|银行", i["secu_name"]):
|
58
|
+
# print(i["secu_name"])
|
59
|
+
|
60
|
+
# 主板, 非ST, 非银行, 非证券
|
61
|
+
if (not re.match(r"^(sz00|sh60)", i["secu_code"])) or re.search(r"ST|银行|证券", i["secu_name"]):
|
62
|
+
continue
|
63
|
+
|
64
|
+
if target in ["up_pool", "up_pool"]:
|
65
|
+
result.append({
|
66
|
+
"code": stock.coderename(i["secu_code"], restore=True),
|
67
|
+
"name": i["secu_name"],
|
68
|
+
"up_days": i["limit_up_days"],
|
69
|
+
"reason": i["up_reason"]
|
70
|
+
})
|
71
|
+
|
72
|
+
if target in ["up_open_pool", "down_pool"]:
|
73
|
+
result.append({
|
74
|
+
"code": stock.coderename(i["secu_code"], restore=True),
|
75
|
+
"name": i["secu_name"]
|
76
|
+
})
|
77
|
+
|
78
|
+
if utils.v_true(df, bool) is False:
|
79
|
+
logger.success(f"{info} [成功]")
|
80
|
+
return result
|
81
|
+
|
82
|
+
# data: pd.DataFrame = pd.DataFrame(response_dict["data"], columns=["secu_code", "secu_name", "limit_up_days", "up_reason"])
|
83
|
+
# data = data.rename(columns={"secu_code": "code", "secu_name": "name", "limit_up_days": "up_days", "up_reason": "reason"})
|
84
|
+
|
85
|
+
return pd.DataFrame(data=pd.DataFrame(result))
|
86
|
+
|
87
|
+
except Exception as e:
|
88
|
+
logger.error(f"{info} [失败]")
|
89
|
+
logger.exception(e)
|
90
|
+
return None
|
91
|
+
|
92
|
+
|
93
|
+
# --------------------------------------------------------------------------------------------------
|
94
|
+
|
95
|
+
|
96
|
+
def latest_data(
|
97
|
+
payload: dict,
|
98
|
+
end: str = "basic",
|
99
|
+
data_type: str = "stock",
|
100
|
+
df: bool = False
|
101
|
+
) -> dict | pd.DataFrame | None:
|
102
|
+
"""股票或板块的最新数据"""
|
103
|
+
|
104
|
+
match True:
|
105
|
+
case True if isinstance(payload, dict) is False:
|
106
|
+
logger.error("Incorrect function argument type: payload")
|
107
|
+
return None
|
108
|
+
case True if isinstance(end, str) is False:
|
109
|
+
logger.error("Incorrect function argument type: end")
|
110
|
+
return None
|
111
|
+
case True if isinstance(data_type, str) is False:
|
112
|
+
logger.error("Incorrect function argument type: data_type")
|
113
|
+
return None
|
114
|
+
case _:
|
115
|
+
pass
|
116
|
+
|
117
|
+
info: str = "获取股票最新数据"
|
118
|
+
|
119
|
+
if utils.v_true(data_type, str) is True and data_type == "plate":
|
120
|
+
info = "获取板块最新数据"
|
121
|
+
|
122
|
+
try:
|
123
|
+
|
124
|
+
logger.info(f"{info} ......")
|
125
|
+
|
126
|
+
user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
|
127
|
+
headers = {"User-Agent": user_agent}
|
128
|
+
|
129
|
+
# https://x-quote.cls.cn/quote/stock/basic?secu_code={code}
|
130
|
+
api = f"https://x-quote.cls.cn/quote/stock/{end}"
|
131
|
+
|
132
|
+
if data_type == "plate":
|
133
|
+
# https://x-quote.cls.cn/web_quote/plate/stocks?secu_code=cls80382
|
134
|
+
# https://x-quote.cls.cn/web_quote/plate/stocks?secu_code={code}
|
135
|
+
# https://x-quote.cls.cn/web_quote/plate/industry?secu_code={code}
|
136
|
+
api = f"https://x-quote.cls.cn/web_quote/plate/{end}"
|
137
|
+
|
138
|
+
# response = requests.get(api, headers=headers, timeout=10)
|
139
|
+
response = requests.get(api, headers=headers, params=payload, timeout=10)
|
140
|
+
|
141
|
+
response_dict: dict = response.json()
|
142
|
+
|
143
|
+
if utils.v_true(df, bool) is False:
|
144
|
+
logger.success(f"{info} [成功]")
|
145
|
+
return response_dict
|
146
|
+
|
147
|
+
if data_type == "plate" and utils.v_true(df, bool) is True:
|
148
|
+
logger.error(f"{info} [错误]")
|
149
|
+
return None
|
150
|
+
|
151
|
+
if response_dict["data"]["trade_status"] == "STOPT":
|
152
|
+
logger.error(f"{info} [停牌]")
|
153
|
+
return None
|
154
|
+
|
155
|
+
data_object = {
|
156
|
+
# "date": [pd.to_datetime(date_today)],
|
157
|
+
"open": [float(response_dict["data"]["open_px"])],
|
158
|
+
"close": [float(response_dict["data"]["last_px"])],
|
159
|
+
"high": [float(response_dict["data"]["high_px"])],
|
160
|
+
"low": [float(response_dict["data"]["low_px"])],
|
161
|
+
"volume": [int(response_dict["data"]["business_amount"])],
|
162
|
+
"turnover": [float(response_dict["data"]["tr"])]
|
163
|
+
}
|
164
|
+
logger.success(f"{info} [成功]")
|
165
|
+
return pd.DataFrame(data=data_object)
|
166
|
+
|
167
|
+
except Exception as e:
|
168
|
+
logger.error(f"{info} [失败]")
|
169
|
+
logger.exception(e)
|
170
|
+
return None
|
@@ -1,11 +1,10 @@
|
|
1
|
-
"""
|
2
|
-
Column, Table, MetaData API
|
3
|
-
|
4
|
-
CursorResult
|
5
|
-
|
6
|
-
PostgreSQL 14 Data Types
|
7
|
-
|
8
|
-
"""
|
1
|
+
"""Database"""
|
2
|
+
# Column, Table, MetaData API
|
3
|
+
# https://docs.sqlalchemy.org/en/14/core/metadata.html#column-table-metadata-api
|
4
|
+
# CursorResult
|
5
|
+
# https://docs.sqlalchemy.org/en/20/core/connections.html#sqlalchemy.engine.CursorResult
|
6
|
+
# PostgreSQL 14 Data Types
|
7
|
+
# https://www.postgresql.org/docs/14/datatype.html
|
9
8
|
import csv
|
10
9
|
from typing import Any
|
11
10
|
|
@@ -1,14 +1,10 @@
|
|
1
|
-
"""
|
2
|
-
企业微信开发者中心
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
https://www.gaoyuanqi.cn/python-yingyong-qiyewx/
|
10
|
-
https://www.jianshu.com/p/020709b130d3
|
11
|
-
"""
|
1
|
+
"""企业微信"""
|
2
|
+
# 企业微信开发者中心
|
3
|
+
# https://developer.work.weixin.qq.com/
|
4
|
+
# https://developer.work.weixin.qq.com/document/path/90313 (全局错误码)
|
5
|
+
# 参考文档:
|
6
|
+
# https://www.gaoyuanqi.cn/python-yingyong-qiyewx/
|
7
|
+
# https://www.jianshu.com/p/020709b130d3
|
12
8
|
import json
|
13
9
|
import time
|
14
10
|
|
@@ -39,12 +35,15 @@ class QYWX:
|
|
39
35
|
def getaccess_token(self) -> str | None:
|
40
36
|
try:
|
41
37
|
response = requests.get(f"{self.url_prefix}/cgi-bin/gettoken?corpid={self.work_id}&corpsecret={self.agent_secret}", timeout=10)
|
42
|
-
|
43
|
-
|
44
|
-
self.access_token = result.get('access_token')
|
45
|
-
else:
|
38
|
+
|
39
|
+
if response.status_code != 200:
|
46
40
|
self.access_token = None
|
41
|
+
return None
|
42
|
+
|
43
|
+
result: dict = response.json()
|
44
|
+
self.access_token = result.get('access_token')
|
47
45
|
return result.get('access_token')
|
46
|
+
|
48
47
|
except Exception as e:
|
49
48
|
logger.exception(e)
|
50
49
|
return None
|
@@ -151,15 +150,19 @@ class QYWX:
|
|
151
150
|
users: list = []
|
152
151
|
|
153
152
|
match True:
|
154
|
-
case True if utils.v_true(mobile, list):
|
153
|
+
case True if isinstance(mobile, list) and utils.v_true(mobile, list):
|
155
154
|
users = mobile
|
156
|
-
case True if utils.v_true(mobile, str):
|
155
|
+
case True if isinstance(mobile, str) and utils.v_true(mobile, str):
|
157
156
|
users.append(mobile)
|
158
157
|
case _:
|
159
|
-
return
|
158
|
+
return False
|
160
159
|
|
161
160
|
for user in users:
|
162
161
|
user_object = self.get_user_id_by_mobile(user)
|
162
|
+
|
163
|
+
if not isinstance(user_object, dict):
|
164
|
+
continue
|
165
|
+
|
163
166
|
json_dict = {
|
164
167
|
'touser': user_object.get('userid'),
|
165
168
|
'msgtype': 'text',
|
@@ -0,0 +1,60 @@
|
|
1
|
+
"""股票"""
|
2
|
+
from copy import deepcopy
|
3
|
+
from typing import Any
|
4
|
+
|
5
|
+
from loguru import logger
|
6
|
+
|
7
|
+
from . import utils
|
8
|
+
|
9
|
+
|
10
|
+
def coderename(target: str | dict, restore: bool = False) -> str | dict | None:
|
11
|
+
"""
|
12
|
+
正向:
|
13
|
+
coderename('000001') => 'sz000001'
|
14
|
+
coderename({'code': '000001', 'name': '平安银行'}) => {'code': 'sz000001', 'name': '平安银行'}
|
15
|
+
反向:
|
16
|
+
coderename('sz000001', restore=True) => '000001'
|
17
|
+
coderename({'code': 'sz000001', 'name': '平安银行'}) => {'code': '000001', 'name': '平安银行'}
|
18
|
+
"""
|
19
|
+
|
20
|
+
try:
|
21
|
+
|
22
|
+
_object: Any = None
|
23
|
+
_code_name: Any = None
|
24
|
+
|
25
|
+
# 判断 target 是 string 还是 dictionary
|
26
|
+
if isinstance(target, str) and utils.v_true(target, str):
|
27
|
+
_code_name = target
|
28
|
+
elif isinstance(target, dict) and utils.v_true(target, dict):
|
29
|
+
_object = deepcopy(target)
|
30
|
+
_code_name = str(deepcopy(target["code"]))
|
31
|
+
else:
|
32
|
+
return None
|
33
|
+
|
34
|
+
# 是否还原
|
35
|
+
if restore:
|
36
|
+
if len(_code_name) == 8 and ("sh" in _code_name or "sz" in _code_name):
|
37
|
+
_code_name = _code_name[2:8]
|
38
|
+
else:
|
39
|
+
return None
|
40
|
+
else:
|
41
|
+
if _code_name[0:2] == "00":
|
42
|
+
_code_name = "sz" + _code_name
|
43
|
+
elif _code_name[0:2] == "60":
|
44
|
+
_code_name = "sh" + _code_name
|
45
|
+
else:
|
46
|
+
return None
|
47
|
+
|
48
|
+
# 返回结果
|
49
|
+
if utils.v_true(target, str):
|
50
|
+
return _code_name
|
51
|
+
|
52
|
+
if utils.v_true(target, dict):
|
53
|
+
_object["code"] = _code_name
|
54
|
+
return _object
|
55
|
+
|
56
|
+
return None
|
57
|
+
|
58
|
+
except Exception as e:
|
59
|
+
logger.exception(e)
|
60
|
+
return None
|
@@ -6,12 +6,14 @@ ezKit/__init__.py
|
|
6
6
|
ezKit/bottle.py
|
7
7
|
ezKit/bottle_extensions.py
|
8
8
|
ezKit/cipher.py
|
9
|
+
ezKit/cls.py
|
9
10
|
ezKit/database.py
|
10
11
|
ezKit/http.py
|
11
12
|
ezKit/mongo.py
|
12
13
|
ezKit/qywx.py
|
13
14
|
ezKit/redis.py
|
14
15
|
ezKit/sendemail.py
|
16
|
+
ezKit/stock.py
|
15
17
|
ezKit/token.py
|
16
18
|
ezKit/utils.py
|
17
19
|
ezKit/xftp.py
|
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
|