Exemple #1
0
def create_app(test_config: Optional[Dict[str, Any]] = None,
               *,
               with_db: bool = True):
    """Application factory."""
    app = Flask("main", static_url_path="", template_folder=cfg.TEMPLATES_DIR)

    # Load the Flask configuration parameters from a global config file.
    app.config.from_object(cfg)

    if test_config:
        app.config.update(test_config)

    if app.debug:
        app.logger.propagate = True

    register_blueprints(app)
    register_extensions(app, test_config=test_config)
    register_route_checks(app)
    register_custom_helpers(app)

    app.jinja_env.lstrip_blocks = True
    app.jinja_env.trim_blocks = True

    if with_db:
        # Connect to the database and initialize SQLAlchemy.
        init_db(app)
    return app
Exemple #2
0
def cli(ctx):
    if not isfile(Const.DB):
        init_db()
    if not isfile(Const.CONFIGS):
        with open(Const.CONFIGS, 'w') as f:
            f.write('2000-01-01 00:00:00.000000\n')
            f.write('2000-01-01 00:00:00.000000\n')
    if ctx.invoked_subcommand is None:
        click.echo(ctx.get_help())
Exemple #3
0
    def __init__(self, settingsFile, tor=False,headless=False):
        """ Initialize Twitter bot

            @param settingsFiles    {String} name of settings file
            @param tor              {Boolean} whether to use tor
        """
        database.init_db()
        self.settings = json.load(open(settingsFile, 'r'))
        self.settings['file'] = settingsFile
        self.tor = tor
        self.logger = logging.getLogger(self.settings['file'])
        self.signedIn = False
        self.phantom = False
        self.headless = headless
        self.twittername = self.settings['twittername']
        self.logger.debug('Initialized')
Exemple #4
0
    def __init__(self, settingsFile, tor=False,headless=False):
        """ Initialize Twitter bot

            @param settingsFiles    {String} name of settings file
            @param tor              {Boolean} whether to use tor
        """
        database.init_db()
        self.settings = json.load(open(settingsFile, 'r'))
        self.settings['file'] = settingsFile
        self.tor = tor
        self.logger = logging.getLogger(self.settings['file'])
        self.signedIn = False
        self.phantom = False
        self.headless = headless
        self.twittername = self.settings['twittername']
        self.logger.debug('Initialized')
Exemple #5
0
def create_app(test_config=None):
    """Application factory."""
    app = Flask('main', static_url_path="", template_folder=cfg.TEMPLATES_DIR)

    # Load the Flask configuration parameters from a global config file.
    app.config.from_object(cfg)

    if test_config:
        app.config.update(test_config)

    register_blueprints(app)
    register_extensions(app, test_config=test_config)
    register_route_checks(app)

    # Connect to the database and initialize SQLAlchemy.
    init_db(app)
    return app
Exemple #6
0
 def __init__(self):
     """Constructor Method
     """
     self.__parameters = { i.replace(' ', '') : None for i in Config.getInstance().get('Parameters', 'parameters.values').split(',') }
     self.__num_parameters = len(self.__parameters)
     self.__mode = None
     self.__id = ''
     self.__username = ''
     self.__password = ''
     self.__conn, self.__cursor = init_db(Config.getInstance().get('Database', 'db.local-uri'))
     self.__set_limits()
Exemple #7
0
def create_app(test_config=None):
    """
        特别注意 因为使用了bp路由会导致 view task main 三个互相依赖 所以在这里要去掉路由 把路由和main 绑定在一起
        当然也可以通过app_name 参数实现 但是需要使用单例模式 否者api和task 会启动两个app 一个提供接口 一个提供对celery的连接 感觉不太合理
    Application factory.
    """
    flask_app = Flask('main')
    flask_app.config.from_object(config)

    if flask_app.debug:
        # 日志传递
        flask_app.logger.propagate = True
    # 注册缓存
    cache.init_app(flask_app)
    register_extensions(flask_app, test_config=test_config)
    register_custom_helpers(flask_app)

    # Connect to the database and initialize SQLAlchemy.
    init_db(flask_app)
    command_app.init_app(flask_app)
    flask_app.before_request_funcs.setdefault(None, []).append(before_req_cache_ip)

    return flask_app
Exemple #8
0
from lib.utils import manually_read_app_config
from lib.utils import measure_execution_time
from lib.vcs_management import get_vcs_handler

if "MYSQL_CONNECTION_NAME" not in os.environ:
    print("[~] Executed outside AppEngine context. Manually loading config.")
    # updates os.environ
    manually_read_app_config()

pd.set_option("display.max_colwidth", -1)

app = Flask(__name__, static_url_path="", template_folder="templates")
# Load the Flask configuration parameters from a global config file.
app.config.from_object("cfg")
# Load SQLAlchemy
init_db(app)
db = DEFAULT_DATABASE.db
# Push one single global flask app context for usage.
ctx = app.app_context()
ctx.push()
# Used for Pandas.
CVE_DB_ENGINE = db.get_engine(app)


def write_highlighted(text, color=Fore.WHITE, crlf=True):
    highlighted = (Style.BRIGHT + color + "%s" + Style.RESET_ALL) % text
    if crlf:
        print(highlighted)
    else:
        sys.stdout.write(highlighted)
Exemple #9
0
    Output : Flask application

    """
    flask_app = Flask(__name__)
    flask_app.debug = True
    flask_app.add_url_rule(
        "/graphql",
        view_func=GraphQLView.as_view("graphql",
                                      schema=schema.schema,
                                      graphiql=True),
    )

    #@flask_app.teardown_appcontext
    #def shutdown_session():
    #    db.db_session.remove()

    return flask_app


if __name__ == "__main__":

    # create some data and add it to the database
    db.init_db()

    app = create_app()

    #If cross origin resource sharing is not enabled, forntend will not be able to access the resource.
    CORS(app, resources={r"/graphql": {"origins": "*"}})

    app.run(host="0.0.0.0")