modify scripts

This commit is contained in:
oscarz
2025-04-07 11:32:49 +08:00
parent d4de5714a6
commit 8f0c5b3eea
3 changed files with 85 additions and 13 deletions

View File

@ -15,15 +15,16 @@ em_market_fs_all = {
}
em_market_fs_types = {
'us_china' : "b:MK0201",
'hk_connect' : "b:DLMK0146,b:DLMK0144",
'hk_china_corps' : "b:DLMK0112",
'cn_kechuang' : "m:1 t:23",
'cn_hs300' : "b:bk0500 f:!50",
#'cn_a500' : "b:bk0701 f:!50",
'hk_famous' : "b:DLMK0106",
'hk_blueclip' : "b:DLMK0105",
'us_famous' : "b:MK0001",
'cn_kechuang' : "m:1 t:23", # 科创板
'cn_hs300' : "b:bk0500 f:!50", # 沪深300
'cn_connect' : "b:BK0707,b:BK0804", # 沪深股通(香港买沪市)
#'cn_sz_hk' : "b:BK0804", # 深股通(香港买深市)
'hk_connect' : "b:DLMK0146,b:DLMK0144", # 港股通
'hk_china_corps' : "b:DLMK0112", # 港股国企成分股
'hk_famous' : "b:DLMK0106", # 港股著名股
'hk_blueclip' : "b:DLMK0105", # 港股蓝筹股
'us_famous' : "b:MK0001", # 美股知名股
'us_china' : "b:MK0201", # 美股中概股
}

View File

@ -0,0 +1,71 @@
import logging
import os
import time
from datetime import datetime
import pandas as pd
import akshare as ak
import src.config.config as config
import src.crawler.em.stock as em
flag_save_to_csv = True
# 写入结果
def save_to_csv(pd, save_path, file_name):
if not flag_save_to_csv:
return None
os.makedirs(save_path, exist_ok=True)
full_name = f"{save_path}/{file_name}"
pd.to_csv(full_name, index=False)
# 中证指数成分股
def get_csindex(symbol='000300'):
df = ak.index_stock_cons_csindex(symbol=symbol)
save_to_csv(df, config.global_host_input_dir, f"csindex_{symbol}.csv")
return df
# sina接口返回指数成分股
def get_sina_index_stock(symbol='000300'):
df = ak.index_stock_cons(symbol="000300")
save_to_csv(df, config.global_host_input_dir, f"sina_index_{symbol}.csv")
return df
# 腾讯接口返回AH股名单
def get_ah_stock():
df = ak.stock_zh_ah_name()
save_to_csv(df, config.global_host_input_dir, f"hk_ah.csv")
# 港股通成分股
def get_hk_ggt_components():
df = ak.stock_hk_ggt_components_em()
save_to_csv(df, config.global_host_input_dir, f"hk_ggt.csv")
# 东财的板块成分股
def get_stock_by_fs():
data_list = []
for key, fs in em.em_market_fs_types.items():
fs_dict = em.code_by_fs(market_id=key, fs=fs) # 返回 {''000255' : '三七互娱'}
for code, name in fs_dict.items():
data_list.append({
'makert': key,
'code': code,
'name': name
})
df = pd.DataFrame(data_list)
save_to_csv(df, config.global_host_input_dir, f"em_index_all.csv")
return df
def refresh_main_index():
#get_csindex(symbol='000300')
#get_csindex(symbol='000510')
#get_sina_index_stock(symbol='000300')
#get_ah_stock()
#get_hk_ggt_components()
get_stock_by_fs()
# 开始处理
if __name__ == "__main__":
refresh_main_index()

View File

@ -182,12 +182,11 @@ def save_to_csv(pd, save_path, file_name):
# 开始处理
if __name__ == "__main__":
stock_files = {
#'hk_game_plat' : f'{config.global_host_input_dir}/hk_game_plat.csv',
#'hk_tech_plat' : f'{config.global_host_input_dir}/hk_tech_plat.csv',
'hk_house_plate' : f'{config.global_host_input_dir}/hk_house_plate.csv',
'hk_game_plat' : f'{config.global_host_input_dir}/hk_game_plat.csv',
'hk_tech_plat' : f'{config.global_host_input_dir}/hk_tech_plat.csv',
#'hk_house_plate' : f'{config.global_host_input_dir}/hk_house_plate.csv',
}
all_results = []
for key, ff in stock_files.items():
df = load_csv(ff)
if df.empty:
@ -195,6 +194,7 @@ if __name__ == "__main__":
continue
# 处理代码
all_results = []
for row in df.itertuples():
stock_code = getattr(row, '代码')
stock_name = getattr(row, '名称')