rquote 0.2.8__py3-none-any.whl → 0.2.9__py3-none-any.whl

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.
rquote/main.py CHANGED
@@ -114,6 +114,29 @@ def get_cn_future_list():
114
114
  return futurelist_active
115
115
 
116
116
 
117
+ def _check_date_format(date_str):
118
+ # 允许格式: 2099-01-01
119
+ if not re.match(r'^\d{4}-\d{2}-\d{2}$', date_str):
120
+ # 尝试转换
121
+ try:
122
+ # 常见格式尝试
123
+ t_struct = None
124
+ for fmt in ("%Y/%m/%d", "%Y%m%d", "%Y.%m.%d", "%Y_%m_%d", "%Y-%m-%d"):
125
+ try:
126
+ t_struct = time.strptime(date_str, fmt)
127
+ break
128
+ except Exception:
129
+ continue
130
+ if t_struct is None:
131
+ raise ValueError(f"date format not recognized: {date_str}")
132
+ # 转换为标准格式
133
+ date_str_std = time.strftime("%Y-%m-%d", t_struct)
134
+ return date_str_std
135
+ except Exception as e:
136
+ raise ValueError(f"date format error: {date_str}, {e}")
137
+ return date_str
138
+
139
+
117
140
  def get_price(i, sdate='', edate='', freq='day', days=320, fq='qfq',
118
141
  dd=None) -> (str, str, pd.DataFrame):
119
142
  '''
@@ -131,6 +154,12 @@ def get_price(i, sdate='', edate='', freq='day', days=320, fq='qfq',
131
154
  logger.debug('loading price from dd {}'.format(i))
132
155
  return i, n, d
133
156
  logger.debug('fetching price of {}'.format(i))
157
+
158
+ # 检查sdate和edate格式
159
+ sdate = _check_date_format(sdate) if sdate else ''
160
+ edate = _check_date_format(edate) if edate else ''
161
+
162
+
134
163
  qtimg_stock = 'http://web.ifzq.gtimg.cn/appstock/app/newfqkline/get?param=' + \
135
164
  '{},{},{},{},{},{}'
136
165
  qtimg_stock_hk = 'http://web.ifzq.gtimg.cn/appstock/app/hkfqkline/get?' + \
@@ -173,8 +202,7 @@ def get_price(i, sdate='', edate='', freq='day', days=320, fq='qfq',
173
202
 
174
203
  if i[:2] == 'fu':
175
204
  try:
176
- ix = i[2:] if i[-1]=='0' else i[2:-4]
177
- if ix == 'btc' or ix == 'BTC':
205
+ if i[2:5].lower() == 'btc':
178
206
  url = sina_btc
179
207
  d = json.loads(hget(url).text)['result']['data'].split('|')
180
208
  d = pd.DataFrame([i.split(',') for i in d],
@@ -430,4 +458,8 @@ def get_hk_stocks_hsi():
430
458
 
431
459
 
432
460
 
461
+ if __name__ == "__main__":
462
+ # print(get_cn_stock_list())
463
+ # print(get_price('fuBTC'))
464
+ print(get_price('sz000001', sdate='20240101', edate='20250101'))
433
465
 
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rquote
3
- Version: 0.2.8
3
+ Version: 0.2.9
4
4
  Summary: Mostly day quotes of cn/hk/us/fund/future markets, side with quote list fetch
5
5
  Requires-Python: >=3.6.1
6
6
  Description-Content-Type: text/markdown
7
7
  Requires-Dist: httpx>=0.20.0
8
8
  Requires-Dist: pandas>=1.0.0
9
- Requires-Dist: setuptools>=59.6.0
9
+ Requires-Dist: setuptools>=42
10
10
  Requires-Dist: twine>=3.8.0
11
11
 
12
12
  # rquote
@@ -0,0 +1,8 @@
1
+ rquote/__init__.py,sha256=PB620yEq2QZyfDweKY_8qMEsZMKhskGfhmfDkch_0j0,462
2
+ rquote/main.py,sha256=SiMpjcs9zvcRzvSMPByX_ZpLQuYRyx2AUEeHJnj8uE4,18272
3
+ rquote/plots.py,sha256=N8uvD6ju9tow0DllPQiXiM7EoPC2bK8X7QF6NQainKs,2342
4
+ rquote/utils.py,sha256=4Neb9_R-EKAd6s1Qj4O_vs9jXWyvroxEEhdqH35vxVE,6808
5
+ rquote-0.2.9.dist-info/METADATA,sha256=QG0nVFxI0ePdTK7894Ajq8H4R2X-PbiRoLMG-h75Q3M,7273
6
+ rquote-0.2.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ rquote-0.2.9.dist-info/top_level.txt,sha256=CehAiaZx7Fo8HGoV2zd5GhILUW1jQEN8YS-cWMlrK9Y,7
8
+ rquote-0.2.9.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- rquote/__init__.py,sha256=PB620yEq2QZyfDweKY_8qMEsZMKhskGfhmfDkch_0j0,462
2
- rquote/main.py,sha256=BzikZQ9tkcn6uJFhK2_tfeWdOnurD7h3uERWoGq6mHg,17180
3
- rquote/plots.py,sha256=N8uvD6ju9tow0DllPQiXiM7EoPC2bK8X7QF6NQainKs,2342
4
- rquote/utils.py,sha256=4Neb9_R-EKAd6s1Qj4O_vs9jXWyvroxEEhdqH35vxVE,6808
5
- rquote-0.2.8.dist-info/METADATA,sha256=PvmiOcaBfbuwBGs47g3saetPEXOwy_zcvu1b31r1iho,7277
6
- rquote-0.2.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
- rquote-0.2.8.dist-info/top_level.txt,sha256=CehAiaZx7Fo8HGoV2zd5GhILUW1jQEN8YS-cWMlrK9Y,7
8
- rquote-0.2.8.dist-info/RECORD,,
File without changes