def dailyStkInfoEmail_input(stk_list): """ 定时器每天要执行的函数,发送所关心的基本的stk信息 :return: """ """ -------------------------- 组织html --------------------------- """ # 构造html的单位 H_str = '' + H_Head # html字符串 date_str = get_current_date_str() # 获取当前日期 pic_dir_list = [] # 用以保存用到的图片的路径 """ 制定html """ for stk in stk_list: stk_df = ts.get_k_data(stk) # 生成图片 pic_dir_stk = genStkPic(stk_df, stk, date_str, pic_save_dir_root, pic_name='stk_A_C_M.png') pic_dir_index = genStkIdxPic(stk_df, stk, date_str, pic_save_dir_root, pic_name='stk_idx.png') pic_dir_list.append(pic_dir_stk) pic_dir_list.append(pic_dir_index) # 构造html H_str = H_str + gen_H_Unit(stk_code=stk, stk_name=getNameByStkCode(g_total_stk_info_mysql, stk), pic_dir=pic_dir_stk.replace(pic_save_dir_root, ''))\ + gen_H_Unit(stk_code=stk, stk_name=getNameByStkCode(g_total_stk_info_mysql, stk), pic_dir=pic_dir_index.replace(pic_save_dir_root, '')) print('完成' + str(stk) + ' 的邮件内容!') H_str = H_str + H_tail """ ------------------- 生成需要的图片 ----------------------- """ msgImage_list = genMIMEImageList(pic_dir_list) """ -------------------- 邮件发送 ----------------------- """ while True: mail_return = sendmail( subject='Darling, daily report for you!', MIMEText_Input=MIMEText(H_str, 'html', 'utf-8'), MIMEImageList=msgImage_list, toaddrs=["your [email protected]", "*****@*****.**"], fromaddr="*****@*****.**", smtpaddr="smtp.163.com", password="******") if mail_return == 0: break else: print('邮件发送失败!原因:' + str(mail_return) + '\n将延时后重发!') time.sleep(20)
def judgeAndSendMsg(): """ 按频率调用, :return: """ if os.path.exists(h_l_pot_info_url): with open(h_l_pot_info_url, 'rb') as f: h_l_pot_info = pickle.load(f) else: print('函数 judgeAndSendMsg: 加载高低信息失败!') return df_H_L_Pot = h_l_pot_info for stk in df_H_L_Pot.index: # 获取该股票的实时价格 current_price = float( ts.get_realtime_quotes(df_H_L_Pot.loc[stk, 'stk'])['price'].values[0]) # 将当前价格保存,用于验证计算准确性 df_H_L_Pot.loc[stk, 'current_price'] = current_price """ 年线判断 """ df_H_L_Pot = lineJudge(df_H_L_Pot_index=stk, current_price=current_price, df_info=df_H_L_Pot, line_str='year') """ ----------------- 半年线判断 -----------------""" df_H_L_Pot = lineJudge(df_H_L_Pot_index=stk, current_price=current_price, df_info=df_H_L_Pot, line_str='half_year') """ ----------------- 月线判断 ----------------""" df_H_L_Pot = lineJudge(df_H_L_Pot_index=stk, current_price=current_price, df_info=df_H_L_Pot, line_str='month') """ 检查并发送消息 """ for idx in df_H_L_Pot.index: # 遍历年线、半年线和月线 for sts in ['year_status', 'half_year_status', 'month_status']: if (df_H_L_Pot.loc[idx, sts] != u'正常') & (df_H_L_Pot.loc[ idx, sts] != df_H_L_Pot.loc[idx, sts + '_last']): send_qq( u'影子', 'stk:' + getNameByStkCode( g_total_stk_info_mysql, df_H_L_Pot.loc[idx, 'stk']) + '\n' + '当前价格:' + str(df_H_L_Pot.loc[idx, 'current_price']) + '\n' + '事件: “' + df_H_L_Pot.loc[idx, sts + '_last'] + '” --> “' + df_H_L_Pot.loc[idx, sts] + '”' + '\n\n') df_H_L_Pot.loc[idx, sts + '_last'] = df_H_L_Pot.loc[idx, sts] with open(h_l_pot_info_url, 'wb') as f: pickle.dump(h_l_pot_info, f) print('函数 judgeAndSendMsg: 完成本次判断!')
(conn_opt, engine_opt) = genDbConn(localDBInfo, db_name) cur = conn_opt.cursor() """ ============================ 命令行输入逻辑 =================================== """ while True: input_str = input('输入你的命令:') # 按空格解析命令 input_split = input_str.split(' ') if len(input_split) == 4: # 插入命令 sql_str_no_reap = 'insert into ' +\ table_history + ' (stk_code, stk_name, amount, price, opt, input_time, reap_flag) values(' + \ "'" + input_split[0] + "'" + ',' + \ "'" + getNameByStkCode(g_total_stk_info_mysql, input_split[0]) + "'" + ',' + \ str(input_split[2]) + ',' + \ str(input_split[3]) + ',' + \ "'" + str(input_split[1]) + "'" + ',' + \ "'" + get_current_datetime_str() + "'" + ',' + \ "false" + \ ');' sql_str_reap = 'insert into ' +\ table_history + ' (stk_code, stk_name, amount, price, opt, input_time, reap_flag) values(' + \ "'" + input_split[0] + "'" + ',' + \ "'" + getNameByStkCode(g_total_stk_info_mysql, input_split[0]) + "'" + ',' + \ str(input_split[2]) + ',' + \ str(input_split[3]) + ',' + \ "'" + str(input_split[1]) + "'" + ',' + \ "'" + get_current_datetime_str() + "'" + ',' + \