qnloft-stock/DB/model/StockBasic.py

43 lines
1.2 KiB
Python

# 定义表格映射类
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import declarative_base
# 创建 StockBasic 映射类
class StockBasic(declarative_base()):
__tablename__ = 'stock_basic'
id = Column(Integer, primary_key=True, autoincrement=True)
ts_code = Column(String, nullable=False, unique=True)
symbol = Column(String, nullable=False)
name = Column(String)
comp_name = Column(String)
comp_name_en = Column(String)
isin_code = Column(String)
exchange = Column(String)
list_board = Column(String)
list_date = Column(String)
delist_date = Column(String)
crncy_code = Column(String)
pinyin = Column(String)
list_board_name = Column(String)
is_shsc = Column(String)
comp_code = Column(String)
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def __repr__(self):
return f"<StockBasic(ts_code='{self.ts_code}', name='{self.name}', exchange='{self.exchange}')>"
def to_dict(self):
# 定义要保留的属性列表
allowed_attributes = ['delist_date', 'is_shsc', 'comp_name', 'comp_name_en']
# 创建字典并添加需要保留的属性
obj_dict = {}
for attr in allowed_attributes:
obj_dict[attr] = getattr(self, attr)
return obj_dict