def create_app(): """ Set up the flask app and initialize global objects """ # Create the flask application app = Flask(__name__) # The ENV environment variable is set in the launch.json file and we default here to production. environment = os.getenv('ENV', 'prod') if environment == 'dev': app.config.from_object(DevConfig()) if environment == 'prod': app.config.from_object(ProdConfig()) # initalize our globlal objects bs.init_app(app) db.init_app(app) migrate.init_app(app, db) toastr.init_app(app) login_manager.init_app(app) login_manager.login_view = 'auth_bp.login' from web.routes.character import character_bp app.register_blueprint(character_bp) from web.routes.entry import entry_bp app.register_blueprint(entry_bp) from web.routes.auth import auth_bp app.register_blueprint(auth_bp) return app
def create_app() -> Flask: """Create task runner app.""" # pylint: disable=W0621 app = Flask(__name__) if app.config["ENV"] == "development": try: from config_cust import DevConfig as DevConfigCust app.config.from_object(DevConfigCust()) except ImportError: from config import DevConfig app.config.from_object(DevConfig()) elif app.config["ENV"] == "test": try: from config_cust import ( TestConfig as TestConfigCust, # type: ignore[attr-defined] ) app.config.from_object(TestConfigCust()) except ImportError: from config import TestConfig app.config.from_object(TestConfig()) else: try: from config_cust import Config as ConfigCust app.config.from_object(ConfigCust()) except ImportError: from config import Config app.config.from_object(Config()) db.init_app(app) executor.init_app(app) redis_client.init_app(app) with app.app_context(): # pylint: disable=C0415 from runner.web import filters, web app.register_blueprint(web.web_bp) app.register_blueprint(filters.filters_bp) return app
def create_app(type="app", test=False): app = Flask(__name__) cfg = DevConfig() if test: cfg = TestConfig() app.config.from_object(cfg) configure_celery(app, tasks.celery) init_mongo(app) register_error_handlers(app) register_routes(app) return app if type == "app" else tasks.celery
def create_app(): """Set up flask app and init global objects""" app = Flask(__name__) # Load in configuration environment = os.getenv('ENV') if environment == 'debug': app.config.from_object(DevConfig()) if environment == 'stage': app.config.from_object(StageConfig()) # initalize global objects db.init_app(app) bs.init_app(app) migrate.init_app(app, db) fa.init_app(app) # toastr.init_app(app) # Login Configuration login_manager.init_app(app) login_manager.login_view = 'auth_bp.login' # login_manager.login_message = 'Please log in...' # login_manager.login_message_category = 'info' # Import parts of our application (add new 'components' here) from web.routes import home, characters, players, parties, auth, errors # Register Blueprints app.register_blueprint(home.home_bp) app.register_blueprint(auth.auth_bp) app.register_blueprint(players.player_bp) app.register_blueprint(characters.character_bp) app.register_blueprint(parties.party_bp) app.register_blueprint(errors.error_bp) # after we're all done, return the application object. It becomes available via flask as app. return app
This file contains all the routes Creation date : 29.08.2019 Modification date : 18.05.2020 """ __author__ = "Tanguy Cavagna" __version__ = "1.0" #endregion from flask import Flask, escape, request, jsonify, render_template, g from python.Earthquake import Earthquake from python.SqliteController import SqliteController from config import DevConfig app = Flask(__name__) app.config.from_object(DevConfig()) app.secret_key = "8185c8ac4656219f4aa5541915079f7b3743e1b5f48bacfcc3386af016b55320" @app.route('/') def home(): """Show the home page """ return render_template('admin.html', countEarthquake=Earthquake().count_all()) #@app.route('/update/activation/<player_id>', methods=['POST']) #def updateActivation(player_id): # updateStatus = Player().updateActivated(player_id, request.form['checked']) # return jsonify({'status': updateStatus}) @app.route('/override', methods=['POST']) def override_all_data():
config.EMAIL_PASSWORD = email_password config.AKM_KEY_ARN = 'arn:aws:kms:ap-northeast-2:774685857155:key/a5ff2eec-197f-4b82-b264-283e72c1644b' return config if __name__ == "__main__": env = os.environ['ENV'] if env == 'STAGING': key_arn = 'arn:aws:kms:ap-northeast-2:774685857155:key/a5ff2eec-197f-4b82-b264-283e72c1644b' config = StagingConfig(key_arn).get_config() else: from config import DevConfig config = DevConfig() app = create_app(config) if env != 'DEV': # For developement, use the default web server so we can # leverage from auto re-loading, debug console, and etc twisted = Twisted(app) log.startLogging(sys.stdout) ## Configure logging if not app.debug: ## Set up the email logging setting mail_handler = NonBlockingSMTPHandler( mailhost=('smtp.gmail.com', 587), fromaddr=config.EMAIL,
from flask_httpauth import HTTPBasicAuth from passlib.apps import custom_app_context as pwd_context from itsdangerous import (TimedJSONWebSignatureSerializer as Serializer, BadSignature, SignatureExpired) from scada import MeasurementController, SerializeDataController, StateController import os, sys import json import logging app = Flask(__name__) CORS(app) if len(sys.argv) > 1 and sys.argv[1] == '-d': AUTH = False Config = DevConfig() else: AUTH = True log = logging.getLogger('werkzeug') log.setLevel(logging.ERROR) Config = DevConfig() # problem z bazą app.config.from_object(Config) db_config = { "host": Config.DB_HOST, "user": Config.DB_USER, "password": Config.DB_PASSWORD, "port": Config.DB_PORT }
def create_app() -> Flask: """Create task runner app.""" # pylint: disable=W0621 app = Flask(__name__) if app.config["ENV"] == "development": try: from config_cust import DevConfig as DevConfigCust app.config.from_object(DevConfigCust()) except ImportError: from config import DevConfig app.config.from_object(DevConfig()) elif app.config["ENV"] == "test": try: from config_cust import ( TestConfig as TestConfigCust, # type: ignore[attr-defined] ) app.config.from_object(TestConfigCust()) except ImportError: from config import TestConfig app.config.from_object(TestConfig()) else: try: from config_cust import Config as ConfigCust app.config.from_object(ConfigCust()) except ImportError: from config import Config app.config.from_object(Config()) db.init_app(app) # pylint: disable=W0611 from scheduler import maintenance # noqa: F401 with contextlib.suppress(SchedulerAlreadyRunningError): # pytest imports twice, this will catch on the second import. atlas_scheduler.init_app(app) logging.basicConfig(level=logging.WARNING) with app.app_context(): # pylint: disable=W0611 if atlas_scheduler.running is False: # pytest imports twice. this will save us on the # second import. atlas_scheduler.start() # pylint: disable=C0415 from apscheduler.events import ( EVENT_JOB_ADDED, EVENT_JOB_ERROR, EVENT_JOB_EXECUTED, EVENT_JOB_MISSED, EVENT_JOB_REMOVED, EVENT_JOB_SUBMITTED, ) from scheduler import web from scheduler.events import ( job_added, job_error, job_executed, job_missed, job_removed, job_submitted, ) app.register_blueprint(web.web_bp) if app.config["ENV"] == "test": logging.getLogger("apscheduler").setLevel(logging.INFO) else: logging.getLogger("apscheduler").setLevel(logging.ERROR) atlas_scheduler.add_listener(job_missed, EVENT_JOB_MISSED) atlas_scheduler.add_listener(job_error, EVENT_JOB_ERROR) atlas_scheduler.add_listener(job_executed, EVENT_JOB_EXECUTED) atlas_scheduler.add_listener(job_added, EVENT_JOB_ADDED) atlas_scheduler.add_listener(job_removed, EVENT_JOB_REMOVED) atlas_scheduler.add_listener(job_submitted, EVENT_JOB_SUBMITTED) @app.errorhandler(404) @app.errorhandler(500) def error_message(error: str) -> Response: """Return error page for 404 and 500 errors including the specific error message.""" return make_response(jsonify({"error": str(error)}), 404) return app
def create_app() -> Flask: """Create app.""" # pylint: disable=W0621 app = Flask(__name__) if app.config["ENV"] == "development": try: from config_cust import DevConfig as DevConfigCust app.config.from_object(DevConfigCust()) except ImportError: from config import DevConfig app.config.from_object(DevConfig()) elif app.config["ENV"] == "test": try: from config_cust import ( TestConfig as TestConfigCust, # type: ignore[attr-defined] ) app.config.from_object(TestConfigCust()) except ImportError: from config import TestConfig app.config.from_object(TestConfig()) else: try: from config_cust import Config as ConfigCust app.config.from_object(ConfigCust()) except ImportError: from config import Config app.config.from_object(Config()) compress.init_app(app) web_assets.init_app(app) # auth login_manager.init_app(app) login_manager.login_view = app.config["LOGIN_VIEW"] login_manager.login_message = app.config["LOGIN_MESSAGE"] sess.init_app(app) # database db.init_app(app) migrate.init_app(app, db, directory=app.config["MIGRATIONS"]) # web cache cache.init_app(app) cache.clear() # run tasks off main thread executor.init_app(app) # redis redis_client.init_app(app) # html min htmlmin.init_app(app) with app.app_context(): # pylint: disable=W0611 from web import cli from web.web import assets # noqa: F401 from web.web import ( admin, auth, connection, dashboard, executors, filters, project, saml_auth, table, task, task_controls, task_edit, task_files, ) app.register_blueprint(saml_auth.login_bp) app.register_blueprint(admin.admin_bp) app.register_blueprint(auth.auth_bp) app.register_blueprint(connection.connection_bp) app.register_blueprint(project.project_bp) app.register_blueprint(task.task_bp) app.register_blueprint(task_controls.task_controls_bp) app.register_blueprint(task_edit.task_edit_bp) app.register_blueprint(task_files.task_files_bp) app.register_blueprint(dashboard.dashboard_bp) app.register_blueprint(table.table_bp) app.register_blueprint(executors.executors_bp) app.register_blueprint(filters.filters_bp) app.register_blueprint(cli.cli_bp) if app.config["DEBUG"]: from flask_debugtoolbar import DebugToolbarExtension toolbar = DebugToolbarExtension() toolbar.init_app(app) assets.cache = False # type: ignore[attr-defined] assets.manifest = False # type: ignore[attr-defined] @app.errorhandler(404) @app.errorhandler(500) def error_message(error: str) -> str: """Return error page for 404 and 500 errors including the specific error message. :param error: error message :return: json web response with error message: .. code-block:: python {"error": "messsage"} """ return render_template( "error.html.j2", message="<strong>" + str(error).replace(":", "</strong>:"), trace=full_stack(), title="That was an error", ) return app
headers = {'Content-Type': 'text/html; charset=utf-8'} root = self.config.root return template.render(assets_url=assets_url, root=root, **data), 200, headers @staticmethod def get_file_content(file: Path): mt = mimetypes.guess_type(file) content = file.read_bytes() try: return content.decode('utf-8'), 200, {'Content-Type': mt[0]} except: return content, 200, {'Content-Type': mt[0]} app = WebsiteMicroService(configs=[LocalConfig(), DevConfig()]) app.register_blueprint(Admin(), url_prefix='admin') if __name__ == '__main__': import sys if len(sys.argv) < 2: print("Command arg missing") elif sys.argv[1] == "run": app.execute("run", project_dir='.', module='website', workspace='local', service='app', auto_reload=True) elif sys.argv[1] == "deploy":
from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from flask_marshmallow import Marshmallow from flask_login import LoginManager from flask_bootstrap import Bootstrap from config import appEnvironment, DevConfig appConfig = None if appEnvironment == 'production': from config import ProdConfig appConfig = ProdConfig() else: appConfig = DevConfig() db = SQLAlchemy() migrate = Migrate() ma = Marshmallow() login_manager = LoginManager() bootstrap = Bootstrap() def create_app(): """Construct the core application.""" app = Flask(__name__, instance_relative_config=False) app.config.from_object(appConfig) db.init_app(app) migrate.init_app(app, db) login_manager.init_app(app) bootstrap.init_app(app)
def test_check_config_dev_config(): # When DevConfig.check_config()
# __purpose__="数据库基本操作" import asyncio # 使用uvloop代替asyncio的eventloop import aiomysql # 日志配置 from pscc.utils.Logconfig import load_my_logging_cfg logger = load_my_logging_cfg("crawler_status") loop = asyncio.get_event_loop() # 导入配置库 from config import DevConfig # 实例数据库配置 mcfg = DevConfig().MySQLCfg() class Control: def __init__(self, *args, **kwargs): self.loop = loop async def conn(self): pool = await aiomysql.create_pool(host=mcfg.host, port=mcfg.port, user=mcfg.user, password=mcfg.password, db=mcfg.database, charset=mcfg.charset, loop=loop) conn = await pool.acquire()
from flask import Flask from config import DevConfig, Config from sqlalchemy.ext.declarative import declarative_base app = Flask(__name__) app.config.from_object(DevConfig) Base = declarative_base() session = DevConfig.Session() from app import views, models
#!/usr/bin/env python from batch_demographics import create_app from config import DevConfig app = create_app(DevConfig()) if __name__ == "__main__": app.run(host="0.0.0.0", port=8000)
#!/usr/bin/env python #-*-coding:utf-8-*- import asyncio try: import uvloop asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) except ImportError as e: pass from pscc.utils.Logconfig import load_my_logging_cfg logger = load_my_logging_cfg("crawler_status") from config import DevConfig """实例化配置""" reqcfg = DevConfig().request rescfg = DevConfig().response async def fetch(url, retry, spider, session, semaphore): """普通请求方式""" with (await semaphore): try: if callable(spider.headers): headers = spider.headers() else: headers = spider.headers async with session.get(url, headers=headers, proxy=spider.proxy(), timeout=int(reqcfg("timeout")),
@staticmethod def auth(auth_request): return auth_request.token == os.getenv('TOKEN') @entry def get(self): return app.blueprints['mail'].post_send( subject='test get entry', body='Manual test', from_addr='*****@*****.**', to_addrs='*****@*****.**') app = MailMicroService(name="sample-mail-microservice", debug=True, configs=[LocalConfig(), DevConfig()]) app.register_blueprint(Admin(), url_prefix='admin') app.register_blueprint(Mail('SMTP_SERVER', 'SMTP_LOGIN', 'SMTP_PASSWD')) XRayContextManager(app, xray_recorder) @app.schedule('rate(1 hour)', name='hourly', description="Mail sent every hour for testing.") @app.schedule('cron(00 15 * * ? *)', name="daily", description="Mail sent at 3pm for testing.") def every_sample(name): """This doc string will serve as schedule event description if not defined.""" app.blueprints['mail'].post_send(subject='test event bridge', body=f"Made by {name}",
imgPath = imgInfo['imagename'] pathTemp = [] for img in imgPath: try: lum_img = mpimg.imread(os.path.join('static/images/imagesA', img)) # 读取图像为数组,值为RGB格式0-255 except: pass lum_imgSmall = misc.imresize( lum_img, 0.3 ) # 传入图像的数组,调整图片大小。scipy.misc.imresize(*args, **kwds):This function is only available if Python Imaging Library (PIL) is installed.使用pip install Pillow安装 misc.imsave(os.path.join(imresizeFN, img), lum_imgSmall) #存储调整大小的图像,用于下一步的图像识别,以及减小网页显示的压力 pathTemp.append(imresizeFN + img[:-4] + '.jpg') #print(pathTemp) imgInfo['imagename'] = pathTemp return imgInfo if __name__ == "__main__": fn_1 = csvReading(fileName_1) fn_2 = csvReading(fileName_2) imageFN = pd.concat([fn_1, fn_2]) #手机app拍摄图像时,信息存储在了两个文件中,需要分别读取后并合并 imageFN.columns = ['imagename', 'time', 'long', 'lat'] #为方便编程,修改framedata的列索引为英文 imgInfo = getPixData(imageFN) # print(imgInfo) conn = sqlite3.connect(DevConfig().DATABASE) #连接数据库 imgInfo.to_sql('imagesinfodf', conn) #将dataframe数据存储到SQlite数据库中,表结构根据framedata索引自动建立
import re from html import unescape from urllib.parse import urljoin import aiohttp from aiohttp import AsyncResolver from lxml import etree import re from pscc.requests import fetch from utils.Logconfig import load_my_logging_cfg logger = load_my_logging_cfg("") from config import DevConfig """实例化配置""" rcfg = DevConfig().request class BaseParser(object): def __init__(self, rule, item=None): self.rule = rule self.item = item self.parsing_urls = [] self.pre_parse_urls = [] self.filter_urls = set() self.done_urls = [] """ 解析子域名 :param http://www.itmain4.com/forum-44-1.html ->"http://itmain4.com"
def test_dev_config(): c = DevConfig() assert c.URL is not None assert c.SESSION_COOKIE_SECURE is False assert c.REMEMBER_COOKIE_SECURE is False