|
@@ -0,0 +1,100 @@
|
|
|
+import os
|
|
|
+import time
|
|
|
+import paramiko
|
|
|
+from flask import Flask, render_template, request, url_for, redirect
|
|
|
+
|
|
|
+# coding=utf-8
|
|
|
+import paramiko
|
|
|
+import pymysql
|
|
|
+
|
|
|
+import logging
|
|
|
+
|
|
|
+
|
|
|
+from logging.handlers import RotatingFileHandler
|
|
|
+
|
|
|
+def make_dir(make_dir_path):
|
|
|
+ path = make_dir_path.strip()
|
|
|
+ if not os.path.exists(path):
|
|
|
+ os.makedirs(path)
|
|
|
+
|
|
|
+def getLogHandler():
|
|
|
+ # 日志地址
|
|
|
+ log_dir_name = "/.log"
|
|
|
+ # 文件名,以日期作为文件名
|
|
|
+ log_file_name = 'logger-' + time.strftime('%Y-%m-%d', time.localtime(time.time())) + '.log'
|
|
|
+ # 创建日志文件
|
|
|
+ log_file_folder = os.path.abspath(
|
|
|
+ os.path.join(os.path.dirname(__file__), os.pardir)) + os.sep + log_dir_name
|
|
|
+ make_dir(log_file_folder)
|
|
|
+ log_file_str = log_file_folder + os.sep + log_file_name
|
|
|
+
|
|
|
+ # 默认日志等级的设置
|
|
|
+ logging.basicConfig(level=logging.INFO)
|
|
|
+ # 创建日志记录器,指明日志保存路径,每个日志的大小,保存日志的上限
|
|
|
+ file_log_handler = RotatingFileHandler(log_file_str, maxBytes=1024 * 1024, backupCount=10, encoding='UTF-8')
|
|
|
+ # 设置日志的格式 发生时间 日志等级 日志信息文件名 函数名 行数 日志信息
|
|
|
+ formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)s - %(message)s')
|
|
|
+ # 将日志记录器指定日志的格式
|
|
|
+ file_log_handler.setFormatter(formatter)
|
|
|
+
|
|
|
+ # 日志等级的设置
|
|
|
+ # file_log_handler.setLevel(logging.WARNING)
|
|
|
+
|
|
|
+ return file_log_handler
|
|
|
+
|
|
|
+app = Flask(__name__)
|
|
|
+# 添加日志配置
|
|
|
+app.logger.addHandler(getLogHandler())
|
|
|
+# 激活上下文
|
|
|
+ctx = app.app_context()
|
|
|
+ctx.push()
|
|
|
+
|
|
|
+# conn = pymysql.connect(
|
|
|
+# host='127.0.0.1',
|
|
|
+# user='root',
|
|
|
+# password='g53743001',
|
|
|
+# db='ip',
|
|
|
+# charset='utf8'
|
|
|
+# )
|
|
|
+conn = pymysql.connect(
|
|
|
+ host='52.69.200.169',
|
|
|
+ user='coffee',
|
|
|
+ password='skyeye',
|
|
|
+ db='Coffee',
|
|
|
+ charset='utf8'
|
|
|
+)
|
|
|
+port = '22'
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+@app.route("/")
|
|
|
+def index():
|
|
|
+ return render_template("index.html", title='ERP WEB')
|
|
|
+
|
|
|
+@app.route("/check_Peel_Output_status",methods=['POST', 'GET'])
|
|
|
+def check_Peel_Output_status():
|
|
|
+ if request.method == 'POST':
|
|
|
+ cur = conn.cursor()
|
|
|
+ #sql = "SELECT * FROM `ferment_container_status` ORDER BY `sn` DESC LIMIT 1 "
|
|
|
+ sql = "SELECT `Peel_Output_1`,`Peel_Output_2` FROM `clean_container_status` ORDER BY `sn` DESC LIMIT 1"
|
|
|
+ #sql = ferment_container_status.query.order_by(text('datetime desc')).first()
|
|
|
+ cur.execute(sql)
|
|
|
+ get_Peel_Output_status = cur.fetchone()
|
|
|
+
|
|
|
+ cur1 = conn.cursor()
|
|
|
+ sql1 = "SELECT `Ferment_Input_1`,`Ferment_Input_2` FROM `ferment_container_status` ORDER BY `sn` DESC LIMIT 1 "
|
|
|
+ cur1.execute(sql1)
|
|
|
+ get_Ferment_Input = cur1.fetchone()
|
|
|
+
|
|
|
+ return render_template('test.html',**locals())
|
|
|
+ return render_template("index.html")
|
|
|
+
|
|
|
+@app.before_request
|
|
|
+def log_each_request():
|
|
|
+ app.logger.info('【請求方法】{}【請求路徑】{}【請求IP】{}'.format(request.method, request.path, request.remote_addr))
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ app.run(debug=True,host = '0.0.0.0' , port=5566)
|
|
|
+
|