def main():
    logger = config_log()

    logger.info("Autenticação no Cartola FC")
    # email = os.environ["USER_CARTOLA"]
    # password = os.environ["PASS_CARTOLA"]
    # token_auth = auth_cartolafc(email, password)

    logger.info("Autenticado com sucesso!")
    rm_endpoints = [
        'partida_rodada', 'busca_clube', 'busca_clube_slug',
        'busca_clube_slug_rodada', 'busca_liga', 'busca_liga_slug'
    ]

    logger.info("Criação de diretório temporário")
    tmp = 'cartolafc-extract\\data\\'
    mkdir(tmp)
    tmp = tmp + '{}.csv'
    logger.info("Criado com sucesso!")

    logger.info("Inicio de extração de dados do Cartola FC")
    for k, v in cartolafc_endpoint.items():
        if k not in rm_endpoints:
            response = get_api(v[0])
            if response != None:
                response = json.loads(response)
                if k in response:
                    df = cartolafc_dataframe(response[k], v[1])
                else:
                    df = cartolafc_dataframe(response, v[1])
                logger.info("Arquivo %s exportado." % (k))

                df.to_csv((tmp).format(k), index=False)
    logger.info("Extração concluida com sucesso.")
示例#2
0
def create_app(config_name):
    app = Flask(__name__)
    Compress(app)

    app.config.from_object(config[config_name])
    app.config['COMPRESS_MIN_SIZE'] = 1024
    app.logger.addHandler(config_log())  # 初始化日志
    config[config_name].init_app(app)

    db = SQLAlchemy(app, use_native_unicode='utf8')

    # https://blog.csdn.net/yannanxiu/article/details/53426359 关于定时任务访问数据库时报错
    # 坑在这2个的区别 db = SQLAlchemy() db = SQLAlchemy(app)
    db.init_app(app)
    db.app = app
    db.create_all()
    login_manager.init_app(app)

    # if 'Linux' in platform.system():
    #     import fcntl
    #     f = open("scheduler.lock", "wb")
    #     try:
    #         fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
    #         scheduler.init_app(app)
    #         scheduler.start()
    #     except:
    #         pass
    #
    #     def unlock():
    #         fcntl.flock(f, fcntl.LOCK_UN)
    #         f.close()
    #
    #     atexit.register(unlock)
    #
    # else:
    scheduler.init_app(app)
    scheduler.start()  # 定时任务启动

    from .api_1_0 import api as api_blueprint
    app.register_blueprint(api_blueprint, url_prefix='/api')

    # from .api_1_0.model import api_1_0 as api_blueprint
    # app.register_blueprint(api_blueprint, url_prefix='/api_1_0')
    return app
示例#3
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    app.logger.addHandler(config_log())  # 初始化日志
    config[config_name].init_app(app)

    # https://blog.csdn.net/yannanxiu/article/details/53426359 关于定时任务访问数据库时报错
    # 坑在这2个的区别 db = SQLAlchemy() db = SQLAlchemy(app)
    db.init_app(app)
    db.app = app
    db.create_all()

    login_manager.init_app(app)
    scheduler.start()  # 定时任务启动

    from .api_1_0 import api as api_blueprint
    app.register_blueprint(api_blueprint, url_prefix='/api')

    # from .api_1_0.model import api_1_0 as api_blueprint
    # app.register_blueprint(api_blueprint, url_prefix='/api_1_0')
    return app
示例#4
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    app.logger.addHandler(config_log())  # 初始化日志
    config[config_name].init_app(app)
    moment.init_app(app)

    # https://blog.csdn.net/yannanxiu/article/details/53426359 关于定时任务访问数据库时报错
    # 坑在这2个的区别 db = SQLAlchemy() db = SQLAlchemy(app)
    db.init_app(app)
    db.app = app
    db.create_all()

    login_manager.init_app(app)
    scheduler.start()  # 定时任务启动

    # from .main import main as main_blueprint
    # app.register_blueprint(main_blueprint)

    # from .pro import pro as pro_blueprint
    # app.register_blueprint(pro_blueprint, url_prefix='/pro')
    #
    # from .DataTool import DataTools as DataTool_blueprint
    # app.register_blueprint(DataTool_blueprint, url_prefix='/dataTool')
    #
    # from .TestCase import TestCases as TestCase_blueprint
    # app.register_blueprint(TestCase_blueprint, url_prefix='/TestCase')
    #
    # from .testpage import testpages as testpage_blueprint
    # app.register_blueprint(testpage_blueprint, url_prefix='/testpage')
    #
    # from .apiManage import apiManages as apiManages_blueprint
    # app.register_blueprint(apiManages_blueprint, url_prefix='/apiManage')

    from .api import api as api_blueprint
    app.register_blueprint(api_blueprint, url_prefix='/api')

    # from .api.model import api as api_blueprint
    # app.register_blueprint(api_blueprint, url_prefix='/api')
    return app
from config import config_log

config_log()
示例#6
0
from config import config_log
from config import BASE_DIR

config_log()  # 使日志模块配置生效
示例#7
0
from config import config_log
from config import BASE_DIR

config_log()  # 使日志模块配置代码生效