def gen_stk_sea_select_pic_sub(stk_code): try: jq_login() # 保存路径 save_dir = sea_select_pic_dir + get_current_date_str() + '/' if not os.path.exists(save_dir): os.makedirs(save_dir) # 准备 小时 和 日线 数据 df_hour = gen_hour_macd_values(stk_code) df_day = get_k_data_JQ(stk_code, 800) # 定义图片名称 file_name = stk_code + '.png' # 生成小时图片 gen_hour_macd_pic_local(df_hour, stk_code, 'jq', '', save_dir + 'h_' + file_name) gen_hour_index_pic_local(df_hour[0], stk_code, save_dir + 'h_idx_' + file_name) gen_day_pic_local(df_day, stk_code, save_dir + 'd_' + file_name) gen_w_m_macd_pic_local(df_day, stk_code, save_dir + 'wm_' + file_name) gen_idx_pic_local(df_day, stk_code, save_dir + 'd_idx_' + file_name) except Exception as e: print('生成股票走势图失败!原因:\n' + str(e)) finally: logout()
def checkSingleStkHourMACD_wx(stk_code, source='jq'): df_30, df_60 = gen_hour_macd_values(stk_code, source=source, title='') l_60 = df_60.tail(3)['MACD'].values l_30 = df_30.tail(3)['MACD'].values if l_60[1] == np.min(l_60): title_str = '60分钟开始上涨' sts = 1 elif l_60[1] == np.max(l_60): title_str = '60分钟开始下跌' sts = 2 elif l_30[1] == np.max(l_30): title_str = '30分钟开始下跌' sts = 3 elif l_30[1] == np.min(l_30): title_str = '30分钟开始上涨' sts = 4 else: title_str = '当前无拐点' sts = 0 # 避免重复发图! if stk_code in MACD_min_last.keys(): if MACD_min_last[stk_code] != sts: send_pic = True MACD_min_last[stk_code] = sts else: send_pic = False else: send_pic = True MACD_min_last[stk_code] = sts if send_pic & (sts != 0): return code2name(stk_code) + '-' + title_str + '\n' else: return ''
from SDK.MyTimeOPT import get_current_date_str, get_current_datetime_str stk_code = '000001' if __name__ == '__main__': jq_login() """ --------------------- 生成相关图片 ------------------------ """ # 保存路径 save_dir = sea_select_pic_dir + get_current_date_str() + '/' if not os.path.exists(save_dir): os.makedirs(save_dir) # 准备 小时 和 日线 数据 df_hour = gen_hour_macd_values(stk_code) df_day = get_k_data_JQ(stk_code, 800) # 定义图片名称 file_name = stk_code + '.png' # 生成小时图片 gen_hour_macd_pic_local(df_hour, stk_code, 'jq', '', save_dir + 'h_' + file_name) gen_hour_index_pic_local(df_hour[0], stk_code, save_dir + 'h_idx_' + file_name) gen_day_pic_local(df_day, stk_code, save_dir + 'd_' + file_name) gen_w_m_macd_pic_local(df_day, stk_code, save_dir + 'wm_' + file_name) gen_idx_pic_local(df_day, stk_code, save_dir + 'd_idx_' + file_name) """ --------------------- 读取图片生成pdf ------------------------ """
def gen_kind_pic(kind, pool): """ 造图片,存本地 :param kind: h:小时 h_idx:小时idx d:天 wm:周、月 idx: 指数 :return: 返回的图片应该 执行page和行号,便于更新! 以多层字典的方式返回结果,第一层区分page,第二层区分行号! """ r_dic = {'Index': {}, 'Buy': {}, 'Concerned': {}} dict_stk_hour = copy.deepcopy(dict_stk_list) jq_login() """ 在外部下载需要的数据,防止多进程中重复连接聚宽 """ for page in dict_stk_hour.keys(): for stk_info in dict_stk_list[page]: stk = stk_info[1] if kind is 'h': r_dic[page][stk + '_d'] = gen_hour_macd_values(stk) elif kind is 'h_idx': r_dic[page][stk + '_d'] = gen_hour_macd_values(stk)[0] elif kind is 'd': r_dic[page][stk + '_d'] = get_k_data_JQ(stk, 400) elif kind is 'wm': r_dic[page][stk + '_d'] = get_k_data_JQ( stk, count=400, end_date=get_current_date_str()).reset_index() elif kind is 'd_idx': r_dic[page][stk + '_d'] = get_k_data_JQ(stk, 400) jq.logout() """ 生成pic """ for page in dict_stk_hour.keys(): for stk_info in dict_stk_list[page]: stk = stk_info[1] # 保存路径 save_dir = hist_pic_dir + get_current_date_str( ) + '/' + stk + kind + '/' file_name = get_current_datetime_str()[:-3].replace( ':', '').replace(' ', '').replace('-', '') + '.png' if not os.path.exists(save_dir): os.makedirs(save_dir) if kind is 'h': r_dic[page][stk + '_res'] = pool.apply_async( gen_hour_macd_pic_local, (r_dic[page][stk + '_d'], stk, 'jq', '', save_dir + file_name)) elif kind is 'h_idx': r_dic[page][stk + '_res'] = pool.apply_async( gen_hour_index_pic_local, (r_dic[page][stk + '_d'], stk, save_dir + file_name)) elif kind is 'd': r_dic[page][stk + '_res'] = pool.apply_async( gen_day_pic_local, (r_dic[page][stk + '_d'], stk, save_dir + file_name)) elif kind is 'wm': r_dic[page][stk + '_res'] = pool.apply_async( gen_w_m_macd_pic_local, (r_dic[page][stk + '_d'], stk, save_dir + file_name)) elif kind is 'd_idx': r_dic[page][stk + '_res'] = pool.apply_async( gen_idx_pic_local, (r_dic[page][stk + '_d'], stk, save_dir + file_name)) # 在字典中保存图片路径 r_dic[page][stk + '_url'] = save_dir + file_name return r_dic
# encoding=utf-8
""" import multiprocessing import time def func(msg): for i in range(3): print(msg) time.sleep(1) return "完成 " + msg if __name__ == "__main__": from DataSource.auth_info import * r = gen_hour_macd_pic_wx(gen_hour_macd_values('000001')) get_k_data_JQ(stk, count=120, end_date=add_date_str(get_current_date_str(), 1), freq='30m') pool = multiprocessing.Pool(processes=4) result = [] r = pool.apply_async(gen_hour_macd_pic_wx, (gen_hour_macd_values('000001'), )) pool.close() pool.join() for res in result: print(res.get()) print("Sub-process(es) done.")