fix entity recognition company mapping initialization with error handling
This commit is contained in:
parent
894ed3fd0d
commit
37aaeb92f6
@ -2,8 +2,13 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import sqlite3
|
||||||
from typing import Dict, List, Optional, Set, Tuple
|
from typing import Dict, List, Optional, Set, Tuple
|
||||||
|
|
||||||
|
from app.utils.logging import get_logger
|
||||||
|
|
||||||
|
LOGGER = get_logger(__name__)
|
||||||
|
|
||||||
# 股票代码正则表达式
|
# 股票代码正则表达式
|
||||||
A_SH_CODE_PATTERN = re.compile(r"\b(\d{6})(\.(?:SH|SZ))?\b", re.IGNORECASE)
|
A_SH_CODE_PATTERN = re.compile(r"\b(\d{6})(\.(?:SH|SZ))?\b", re.IGNORECASE)
|
||||||
HK_CODE_PATTERN = re.compile(r"\b(\d{4})\.HK\b", re.IGNORECASE)
|
HK_CODE_PATTERN = re.compile(r"\b(\d{4})\.HK\b", re.IGNORECASE)
|
||||||
@ -132,11 +137,22 @@ def initialize_company_mapping(db_connection) -> None:
|
|||||||
db_connection: SQLite数据库连接
|
db_connection: SQLite数据库连接
|
||||||
"""
|
"""
|
||||||
cursor = db_connection.cursor()
|
cursor = db_connection.cursor()
|
||||||
cursor.execute("""
|
try:
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
SELECT ts_code, name, short_name
|
SELECT ts_code, name, short_name
|
||||||
FROM stock_company
|
FROM stock_company
|
||||||
WHERE name IS NOT NULL
|
WHERE name IS NOT NULL
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
except sqlite3.OperationalError as exc: # pragma: no cover - defensive
|
||||||
|
LOGGER.debug(
|
||||||
|
"stock_company 表不存在,跳过公司映射初始化 err=%s",
|
||||||
|
exc,
|
||||||
|
extra={"stage": "entity_recognition"},
|
||||||
|
)
|
||||||
|
cursor.close()
|
||||||
|
return
|
||||||
|
|
||||||
for ts_code, name, short_name in cursor.fetchall():
|
for ts_code, name, short_name in cursor.fetchall():
|
||||||
if name and short_name:
|
if name and short_name:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user