def download_fq_data_from_tushare(code):
'''
??????????????????????????????
:param code:
:return:
'''
path = './data/'
import tushare as ts
import datetime
sh_index_lastday = open(path+'sh.csv', 'rb').readlines()[1:][-1] # ???????????????????????
# if os.path.exists(path+'stock_data/' + str(code) + '.csv'):
# import tushare as ts
#
# f = open(path+'stock_data/' + str(code) + '.csv', 'rb').readlines()[1:]
# # 3years line
# fp_data = ts.get_h_data(str(code), start=f[-1].split(',')[0], end=f[0].split(',')[0])
# if fp_data is not None:
# fp_data.to_csv(path+"stock_data/"+str(code)+'_fq.csv')
# # ts.get_h_data(str(code), start=raw_dates[0], end=raw_dates[-1]).to_csv(path+"stock_data/"+str(code)+'_fq.csv')
# return True
# else:
# return False
# else:
# return False
years = 3
start = datetime.datetime.today().date() + datetime.timedelta(-365 * years)
# 3years line
# fp_data = ts.get_h_data(str(code), start=str(start))
fp_data = ts.get_k_data(str(code), start=str(start))
if fp_data is not None and len(fp_data) > 1 and fp_data['date'].tolist()[-1] == sh_index_lastday.split(',')[1]:
fp_data.to_csv(path + "stock_data/" + str(code) + '_fq.csv')
return True
else:
return False
评论列表
文章目录