update exportdata
This commit is contained in:
@@ -143,10 +143,54 @@ class DataExporter:
|
||||
self.logger.error("无法获取月度均价数据")
|
||||
return False
|
||||
|
||||
# 读取港股通标记
|
||||
hk_inout_data = self.get_hk_inout()
|
||||
|
||||
for item in monthly_data:
|
||||
stock_name = item.get('stock_code')[3:]
|
||||
if stock_name in hk_inout_data:
|
||||
item['in_out'] = 1
|
||||
else:
|
||||
item['in_out'] = 0
|
||||
|
||||
# 导出结果
|
||||
file_path = 'data/' + csv_file if csv_file else None
|
||||
csv_success = True
|
||||
if csv_file:
|
||||
csv_success = self.export_to_csv(monthly_data, file_path)
|
||||
|
||||
return csv_success
|
||||
return csv_success
|
||||
|
||||
def get_hk_inout(self) -> Optional[List[Dict]]:
|
||||
"""
|
||||
从conditionalselection表读取流通股本数据
|
||||
|
||||
Args:
|
||||
table_name: 源数据表名
|
||||
|
||||
Returns:
|
||||
List[Dict]: 查询结果数据集,失败返回None
|
||||
"""
|
||||
try:
|
||||
with MySQLHelper(**self.db_config) as db:
|
||||
# 查询流通股本数据
|
||||
data = db.execute_query(f"""
|
||||
SELECT stock_code
|
||||
FROM hk_stock_connect
|
||||
WHERE in_out = '1'
|
||||
ORDER BY stock_code
|
||||
""")
|
||||
|
||||
if not data:
|
||||
self.logger.error(f"获取数据失败")
|
||||
return None
|
||||
|
||||
return [
|
||||
row['stock_code']
|
||||
for row in data
|
||||
if row['stock_code']
|
||||
]
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"从数据库读取流通股本数据失败: {str(e)}")
|
||||
return None
|
||||
Reference in New Issue
Block a user