feat(home): 股票列「最热」改为「AI最热」,聚合 AI 概念板块
- 选项卡「最热」→「AI最热」,列标题「当天最热股票」→「AI最热股票」 - 数据源:全市场涨幅榜 → 聚合 12 个 AI 概念板块(人工智能/AI芯片/算力概念/AI应用/AI智能体/多模态AI/AIGC/CPO/智谱AI/AI语料/国产芯片/存储芯片)约 580 只成分股去重 - 排序改为按成交额降序取前 10(涨幅榜被小盘股占据,成交额榜才是资金关注的主线龙头),行内显示「现价 · 成交额」 - 交易时段 60s 自动刷新,标题行保留 交易中/休市 徽章;自选股选项卡不变 - About.vue 功能说明同步更新
This commit is contained in:
1 parent
a7ce1ee79e
commit
c7586f9c63
5 files changed
+80
-11
No files matched your search
@@ -2613,6 +2613,22 @@ _ITHOME_RSS = "https://www.ithome.com/rss/" # IT之家:权威中文 IT 资讯
|
||||
_STOCK_URL = ("https://push2.eastmoney.com/api/qt/clist/get?pn=1&pz=10&po=1&np=1"
|
||||
"&fltt=2&invt=2&fid=f3&fs=m:0+t:6,m:0+t:80,m:1+t:2,m:1+t:23&fields=f12,f14,f3")
|
||||
|
||||
# AI 相关概念板块(东方财富 board code)——「AI 最热」股票列的股票池来源
|
||||
_AI_STOCK_BOARDS = [
|
||||
"BK0800", # 人工智能
|
||||
"BK1127", # AI 芯片
|
||||
"BK1134", # 算力概念
|
||||
"BK1629", # AI 应用
|
||||
"BK0809", # AI 智能体
|
||||
"BK1153", # 多模态 AI
|
||||
"BK1111", # AIGC 概念
|
||||
"BK1128", # CPO 概念
|
||||
"BK1182", # 智谱 AI 概念
|
||||
"BK1172", # AI 语料
|
||||
"BK0891", # 国产芯片
|
||||
"BK1137", # 存储芯片
|
||||
]
|
||||
|
||||
|
||||
def _cst_now():
|
||||
return _dt.now(_CST)
|
||||
@@ -2716,6 +2732,48 @@ def _fetch_stock():
|
||||
return out
|
||||
|
||||
|
||||
def _fetch_ai_stock():
|
||||
"""「AI 最热」:聚合 AI 概念板块成分股,按成交额降序取前 10。
|
||||
用成交额而非涨幅排序——涨幅榜常年被小盘股占据,成交额榜才是资金真正关注的主线龙头。"""
|
||||
pool = {}
|
||||
for bk in _AI_STOCK_BOARDS:
|
||||
url = ("https://push2.eastmoney.com/api/qt/clist/get?pn=1&pz=200&po=1&np=1"
|
||||
"&fltt=2&invt=2&fid=f6"
|
||||
f"&fs=b:{bk}&fields=f2,f3,f6,f12,f14")
|
||||
try:
|
||||
j = json.loads(_http_get(OPENER_DIRECT, url))
|
||||
except Exception as e: # noqa: BLE001
|
||||
print(f"[news] ai board {bk} failed: {e}", flush=True)
|
||||
continue
|
||||
diff = ((j.get("data") or {}).get("diff")) or []
|
||||
if isinstance(diff, dict):
|
||||
diff = list(diff.values())
|
||||
for r in diff:
|
||||
code, name = str(r.get("f12") or ""), str(r.get("f14") or "")
|
||||
pct, price, turn = r.get("f3"), r.get("f2"), r.get("f6")
|
||||
if not code or not name or not isinstance(pct, (int, float)):
|
||||
continue
|
||||
turn = turn if isinstance(turn, (int, float)) else 0
|
||||
# 同一只股票可能属于多个板块,取最大成交额并集
|
||||
if code not in pool or turn > pool[code]["turn"]:
|
||||
pool[code] = {"code": code, "name": name, "pct": pct,
|
||||
"price": price, "turn": turn}
|
||||
if not pool:
|
||||
return []
|
||||
today = _cst_now().strftime("%m-%d")
|
||||
out = []
|
||||
for s in sorted(pool.values(), key=lambda x: -x["turn"])[:10]:
|
||||
price = s["price"]
|
||||
price_s = f"{price}" if isinstance(price, (int, float)) else "-"
|
||||
out.append({
|
||||
"title": f"{s['name']} {s['code']} {s['pct']:+.2f}%",
|
||||
"desc": f"现价 {price_s} · 成交额 {s['turn'] / 1e8:.1f}亿",
|
||||
"url": f"https://quote.eastmoney.com/{s['code']}.html",
|
||||
"time": today,
|
||||
})
|
||||
return out
|
||||
|
||||
|
||||
_STOCK_QUOTE_CACHE = {"t": 0, "key": "", "val": []}
|
||||
|
||||
|
||||
@@ -2854,7 +2912,7 @@ def _fetch_news():
|
||||
lambda: _parse_rss(_http_get(OPENER_PROXY, _TC_AI_RSS)))
|
||||
_col("it", "IT\u6700\u65b0\u6280\u672f", "\U0001f4bb",
|
||||
lambda: _parse_rss(_http_get(OPENER_DIRECT, _ITHOME_RSS)))
|
||||
_col("stock", "\u5f53\u5929\u6700\u70ed\u80a1\u7968", "\U0001f4c8", _fetch_stock)
|
||||
_col("stock", "AI\u6700\u70ed\u80a1\u7968", "\U0001f4c8", _fetch_ai_stock)
|
||||
|
||||
# 翻译:world/ai 英文标题与简介、github 英文简介(it=IT之家中文、stock 中文均免翻)
|
||||
en_title_keys = {"world", "ai"}
|
||||
@@ -2930,14 +2988,14 @@ def _market_status():
|
||||
|
||||
|
||||
def _refresh_stock_if_stale(data, max_age=60):
|
||||
"""「当天最热股票」列高频刷新:交易时段内按需重抓(其余 4 列仍每天 08:00 更新)。
|
||||
"""「AI 最热股票」列高频刷新:交易时段内按需重抓(其余 4 列仍每天 08:00 更新)。
|
||||
失败/非交易时段直接返回原数据,绝不影响 /news 正常返回。"""
|
||||
try:
|
||||
if not data.get("columns") or not _is_trading_time():
|
||||
return data
|
||||
if time.time() - float(data.get("stock_updated") or 0) < max_age:
|
||||
return data
|
||||
fresh = _fetch_stock()
|
||||
fresh = _fetch_ai_stock()
|
||||
if not fresh:
|
||||
return data
|
||||
for c in data["columns"]:
|
||||
|
||||
Reference in new issue
Block a user