def others_1_page(): if "download" in request.args: result, info = others_man.select_others_info(1) if result is False: return info tmp_dir = "/tmp" file_name = "猝死风险预测.%s.xls" % int(time() * 1000) download_file = "%s/%s" % (tmp_dir, file_name) titles = ["患者姓名", "患者联系电话", "最大室壁厚度(mm)", "左房内径(mm)", "最大(静息/Valsalva动作)左心室流出道压力阶差(mmHg)", "心源性猝死家族史", "NSVT", "不能解释晕厥", "临床评估年龄(岁)", "5年心源性猝死可能性", "计算时间"] keys = ["extra_name", "extra_tel", "max_shibihoudu", "zuofangneijing", "yalijiecha", "cusijiazushi", "nsvt", "hunjue", "age", "kenengxing"] array_a = [] for item in info: item_a = [] result_info = json.loads(item["result_info"]) for key in keys: item_a.append(result_info[key]) item_a.append(unix_timestamp(item["insert_time"], style="datetime")) array_a.append(item_a) cols_width = [10, 15, 18, 13, 49, 16, 9, 18, 18, 19, 18] print write_excel(download_file, array_a=array_a, titles=titles, cols_width=cols_width) g.download_file = download_file return send_from_directory(tmp_dir, file_name, attachment_filename="猝死风险预测.xls", as_attachment=True) return render_template("%s/calcIndex.html" % html_dir)
def send_login_info_func(): if current_env != "Production" and current_env != "Development": return result, info = control.register_login_task() if result is False: print("register login task fail") return print("start run login task %s" % info["task_no"]) result, info = control.get_login_info() table_content = "" if len(info["login_records"]) <= 0: print("No Login Records") return for item in info["login_records"]: tr_content = '<tr>' tr_content += '<td>%s</td>\n' % ip_str(item["server_ip"]) # unix_timestamp(item["run_begin"]) tr_content += '<td>%s</td>\n' % item["server_name"] tr_content += '<td>%s</td>' % ip_str(item["user_ip"]) tr_content += '<td>%s</td>\n' % item["user_name"] tr_content += '<td>%s</td>\n' % unix_timestamp(item["login_time"], style="datetime") tr_content += '</tr>\n' table_content += tr_content with open("../Web/templates/LOG/Login_Log.html") as rt: content = rt.read() content = content.replace("{{ TR }}", table_content.encode("utf-8")) subject = u"有用户登录到服务器" my_email.send_mail("*****@*****.**", subject, content) print("send success")
def send_log_func(): if current_env != "Production" and current_env != "Development": return result, info = control.register_log_task() if result is False: print("register log task fail") return print("start run log task %s" % info["task_no"]) result, info = control.get_daily_log() table_content = "" for item in info["log_records"]: tr_content = '<tr title="info: %s host: %s">' % (item["info"].replace(">", ">").replace('"', """), item["host"]) tr_content += '<td name="run_begin" class="status_move">%s</td>\n' % unix_timestamp(item["run_begin"]) tr_content += '<td name="request_url">%s</td>\n' % item["url"] tr_content += '<td>%s</td>' % item["method"] tr_content += '<td name="request_account">%s</td>\n' % item["account"] if item["level"] == "error": level_class = "redBg" elif item["level"] == "base_error": level_class = "orgBg" elif item["level"] == "bad_req": level_class = "yellowBg" elif item["level"] == "http_error": level_class = "greenBg" else: level_class = "" tr_content += '<td name="log_level" class="%s">%s</td>\n' % (level_class, item["level"]) if item["run_time"] >= 1: tr_content += '<td class="redBg">%s</td>' % item["run_time"] elif item["run_time"] >= 0.5: tr_content += '<td class="orgBg">%s</td>' % item["run_time"] else: tr_content += '<td>%s</td>' % item["run_time"] tr_content += "\n" tr_content += '<td name="request_ip">%s</td>' % ip_str(item["ip"]) tr_content += "\n" tr_content += '</tr>\n' table_content += tr_content with open("../Web/templates/LOG/Daily_Log.html") as rt: content = rt.read() content = content.replace("{{ TR }}", table_content.encode("utf-8")) control.send_daily_log(content)