ezKit 1.9.5__tar.gz → 1.9.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.1
2
2
  Name: ezKit
3
- Version: 1.9.5
3
+ Version: 1.9.6
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -99,7 +99,7 @@ def kdj_vector(
99
99
  case True if not utils.isTrue(df, DataFrame):
100
100
  logger.error("argument error: df")
101
101
  return None
102
- case True if True not in [utils.isTrue(kdj_options, tuple), all(utils.isTrue(item, int) for item in kdj_options)]:
102
+ case True if not any([utils.isTrue(kdj_options, tuple), all(utils.isTrue(item, int) for item in kdj_options)]):
103
103
  logger.error("argument error: kdj_options")
104
104
  return None
105
105
  case _:
@@ -133,10 +133,10 @@ def data_vector(
133
133
  case True if not utils.isTrue(df, DataFrame):
134
134
  logger.error("argument error: df")
135
135
  return None
136
- case True if True not in [utils.isTrue(macd_options, tuple), all(utils.isTrue(item, int) for item in macd_options)]:
136
+ case True if not any([utils.isTrue(macd_options, tuple), all(utils.isTrue(item, int) for item in macd_options)]):
137
137
  logger.error("argument error: macd_options")
138
138
  return None
139
- case True if True not in [utils.isTrue(kdj_options, tuple), all(utils.isTrue(item, int) for item in kdj_options)]:
139
+ case True if not any([utils.isTrue(kdj_options, tuple), all(utils.isTrue(item, int) for item in kdj_options)]):
140
140
  logger.error("argument error: kdj_options")
141
141
  return None
142
142
  case _:
@@ -249,8 +249,8 @@ def get_stock_data_from_akshare(
249
249
  end_date: str = "20500101",
250
250
  timeout: float = 10
251
251
  ) -> DataFrame | None:
252
- """从 akshare 获取数据"""
253
- info = f"获取股票所有数据: {code}"
252
+ """从 akshare 获取股票数据"""
253
+ info = f"获取股票数据: {code}"
254
254
  try:
255
255
  logger.info(f"{info} ......")
256
256
  # https://akshare.akfamily.xyz/data/stock/stock.html#id22
@@ -276,17 +276,37 @@ def get_stock_data_from_akshare(
276
276
  # --------------------------------------------------------------------------------------------------
277
277
 
278
278
 
279
- def save_data_to_database(engine: Engine, code: str) -> bool:
280
- """保存股票数据到数据库"""
281
- info: str = "保存股票数据到数据库"
279
+ def save_data_to_database(engine: Engine, code: str, latest: bool = False) -> bool:
280
+ """保存股票所有数据到数据库"""
281
+
282
+ # 默认将所有数据保存到数据库中的表里
283
+ # 如果 latest 为 True, 插入最新的数据到数据库中的表里
284
+ # 即: 将最后一条数据插入到数据库中的表里
285
+
286
+ info: str = "保存股票所有数据到数据库"
287
+
288
+ if utils.isTrue(latest, bool):
289
+ info = "保存股票最新数据到数据库"
290
+
282
291
  try:
292
+
283
293
  logger.info(f"{info} ......")
294
+
284
295
  df: DataFrame | None = get_stock_data_from_akshare(code)
296
+
285
297
  if df is None:
286
298
  return False
287
- df.to_sql(name=code, con=engine, if_exists="replace", index=False)
299
+
300
+ if utils.isTrue(latest, bool):
301
+ df = df.tail(1)
302
+ df.to_sql(name=code, con=engine, if_exists="append", index=False)
303
+ else:
304
+ df.to_sql(name=code, con=engine, if_exists="replace", index=False)
305
+
288
306
  logger.success(f"{info} [成功]")
307
+
289
308
  return True
309
+
290
310
  except Exception as e:
291
311
  logger.success(f"{info} [失败]")
292
312
  logger.exception(e)
@@ -55,6 +55,10 @@ def isTrue(
55
55
  #
56
56
  # isTrue("abc", (str, int))
57
57
  # isTrue("abc", (str | int))
58
+ #
59
+ # all() 用于检查一个可迭代对象(如列表、元组、集合等)中的 所有 元素是否为 真值 (truthy), 所有元素为真, 返回 True
60
+ # any() 用于检查一个可迭代对象(如列表、元组、集合等)中的 某个 元素是否为 真值 (truthy), 某个元素为真, 返回 True
61
+ # 与 all() 作用相反的 not any(), 可以用来检查所有元素是否为 假值 (falsy), any() 中所有元素为假, not any() 返回 True
58
62
 
59
63
  try:
60
64
 
@@ -165,7 +169,7 @@ def mam_of_numbers(
165
169
  case True if not isTrue(numbers, (list, tuple)):
166
170
  logger.error("argument error: numbers")
167
171
  return None
168
- case True if True not in [isTrue(dest_type, str), dest_type is None]:
172
+ case True if not any([isTrue(dest_type, str), dest_type is None]):
169
173
  logger.error("argument error: dest_type")
170
174
  return None
171
175
  case _:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ezKit
3
- Version: 1.9.5
3
+ Version: 1.9.6
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -3,7 +3,7 @@ from setuptools import find_packages, setup
3
3
 
4
4
  setup(
5
5
  name='ezKit',
6
- version='1.9.5',
6
+ version='1.9.6',
7
7
  author='septvean',
8
8
  author_email='septvean@gmail.com',
9
9
  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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes