__init__.py 2.1 KB
import requests
import threading
from flask import Flask
from flask_babel import Babel
from config import Config
import logging
from logging.handlers import RotatingFileHandler,TimedRotatingFileHandler
#from flask_cors import CORS
global Serl
Serl=None

def setup_log():
    # 设置日志的记录等级
    logging.basicConfig(level=Config.LOG_LEVEL)  # 调试debug级
    # 创建日志记录器,指明日志保存的路径、每个日志文件的最大大小、保存的日志文件个数上限
    file_log_handler = RotatingFileHandler(Config.LOG_FOLDER, maxBytes=1024 * 1024 * 100, backupCount=10)
    # 创建日志记录的格式 日志等级 输入日志信息的文件名 行数 日志信息
    # log_file_handler = TimedRotatingFileHandler(filename='logs/smartshelf.log', when="D", interval=1, backupCount=3)
    formatter = logging.Formatter('%(asctime)s - %(levelname)s :  %(message)s')
    # 为刚创建的日志记录器设置日志记录格式
    file_log_handler.setFormatter(formatter)
    file_log_handler.setLevel(logging.WARNING)
    # 为全局的日志工具对象(flask app使用的)添加日志记录器
    logging.getLogger().addHandler(file_log_handler)


def add_header(response):
    response.cache_control.no_store = True
    response.cache_control.no_cache = True
    #if 'Cache-Control' not in response.headers:
    #    response.headers['Cache-Control'] = 'no-cache'
    return response

setup_log()
app = Flask(__name__)
#CORS(app, resources=r'/*')
babel = Babel(app)
app.config.from_object(Config)
app.after_request(add_header)
app.config["LANGUAGES"] = {
        "zh": "Chinese",
        "en": "English",
        "ja": "Japanese"
}

from app import config_ip,induction_post,induction_test,induction_admin,induction_config,autoback,qr_code,scan_collection
from app.induction_config import testCidExists
import time
def s():
    time.sleep(10)
    data = {'key1':'value1','key2':'value2'}
    time.sleep(2)
    requests.post("http://127.0.0.1:5000/stoppost",data)
    #if testCidExists():
    time.sleep(2)
    requests.post("http://127.0.0.1:5000/startpost",data)

t =threading.Thread(target=s)
t.start()
# 	return app