更新 gupiao/scripts/gupiao.py
This commit is contained in:
parent
1c03e00f85
commit
195d8eca99
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
import urllib.error
|
import urllib.error
|
||||||
@ -11,7 +12,7 @@ import urllib.request
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
sys.stderr = sys.stdout
|
# 注意:不重定向 stderr,让框架单独处理错误输出
|
||||||
|
|
||||||
# ---------- 路径配置 ----------
|
# ---------- 路径配置 ----------
|
||||||
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
@ -215,8 +216,7 @@ def parse_symbol_shares(combined: str) -> tuple[str | None, int | None]:
|
|||||||
"""解析合并格式,如「苹果股票13股」→ (苹果, 13)。"""
|
"""解析合并格式,如「苹果股票13股」→ (苹果, 13)。"""
|
||||||
raw = combined.strip()
|
raw = combined.strip()
|
||||||
# 提取尾部数字, support 13 or 13股
|
# 提取尾部数字, support 13 or 13股
|
||||||
import re as _re
|
m = re.search(r'(\d+)(?:股)?$', raw)
|
||||||
m = _re.search(r'(\d+)(?:股)?$', raw)
|
|
||||||
if not m:
|
if not m:
|
||||||
return None, None
|
return None, None
|
||||||
shares = int(m.group(1))
|
shares = int(m.group(1))
|
||||||
@ -539,8 +539,7 @@ def main() -> int:
|
|||||||
uid = args[1]
|
uid = args[1]
|
||||||
|
|
||||||
# 判断 args[2] 是否为合并格式(含数字),如「苹果股票13股」
|
# 判断 args[2] 是否为合并格式(含数字),如「苹果股票13股」
|
||||||
import re as _re2
|
if re.search(r'\d', args[2]):
|
||||||
if _re2.search(r'\d', args[2]):
|
|
||||||
sym_raw, shares_num = parse_symbol_shares(args[2])
|
sym_raw, shares_num = parse_symbol_shares(args[2])
|
||||||
if sym_raw is None or shares_num is None:
|
if sym_raw is None or shares_num is None:
|
||||||
print("❌ 格式错误,示例: buy 腾讯 10 或 buy 腾讯股票10股")
|
print("❌ 格式错误,示例: buy 腾讯 10 或 buy 腾讯股票10股")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user