Example #1
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)
    bootstrap.init_app(app)
    mail.init_app(app)
    moment.init_app(app)
    admin.init_app(app)
    login_manager.init_app(app)
    # Explicitly creating db session using engine with options
    # to fix PythonAnywhere 5 minute timeout issue using pool_recycle
    print('SQLALCHEMY_DATABASE_URI: ', app.config['SQLALCHEMY_DATABASE_URI'])
    app.config['SQLALCHEMY_POOL_RECYCLE'] = 400
    # app.config['SQLALCHEMY_POOL_TIMEOUT'] = 20
    db.init_app(app)
    # engine = create_engine(
    #     app.config['SQLALCHEMY_DATABASE_URI'], pool_recycle=240)
    # db.session = db.scoped_session(
    #     db.sessionmaker(autocommit=False, autoflush=False, bind=engine)
    # )

    # attach routes and custom error pages here
    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    from .auth import auth as auth_blueprint
    app.register_blueprint(auth_blueprint, url_prefix='/auth')

    return app
Example #2
0
                          as Serializer, BadSignature, SignatureExpired)

app = Flask(__name__)

db = flask_sqlalchemy.SQLAlchemy(app)
CORS(app)
manager = APIManager(app, flask_sqlalchemy_db=db)

Base = declarative_base()
metadata = Base.metadata
origin = '*'

app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:root@127.0.0.1/mydb'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_POOL_SIZE'] = 10
app.config['SQLALCHEMY_POOL_RECYCLE'] = 55

class Customers(Base):
    __tablename__='customers'
    name=Column(String(100),primary_key=True)
    address=Column(String(100))

class Players(Base):
    __tablename__='players_new'
    ID=Column(BigInteger, primary_key = True)
    name=Column(String(100))
    date_of_birth=Column(String(100))
    awards_no=Column(String(100))
    career_start_year=Column(String(100))
    career_end_year=Column(String(100))
Example #3
0
File: wicm.py Project: T-NOVA/WICM
    config.getint('opendaylight', 'port'),
    config.get('opendaylight', 'username'),
    config.get('opendaylight', 'password')
))

vtn = VtnWrapper(
    config.get('opendaylight', 'host'),
    config.get('opendaylight', 'port'),
    config.get('opendaylight', 'username'),
    config.get('opendaylight', 'password')
)


app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = mysql_connect
app.config['SQLALCHEMY_POOL_RECYCLE'] = 299  # compatibility with MariaDB
db.init_app(app)


@app.route('/nap', methods=['POST', 'GET', 'DELETE'], strict_slashes=False)
@app.route('/nap/<string:mkt_id>', methods=['GET', 'DELETE'],
           strict_slashes=False)
def nap_request(mkt_id=None):

    if request.method == 'POST':
        nap_request = request.json
        logger.info('Request to create NAP: {}'.format(nap_request))

        client_mkt_id = nap_request['nap']['client_mkt_id']
        mkt_id = nap_request['nap']['mkt_id']
        ce = (nap_request['nap']['switch'], nap_request['nap']['ce_port'],
Example #4
0
from flask import Flask
from flask.ext.misaka import Misaka

from monkblog.settings import APP_STATIC, DATABASE_URI, CONNECTION_POOL_RECYCLE

app = Flask(__name__)
Misaka(app, fenced_code=True)
app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI
app.config['SQLALCHEMY_POOL_RECYCLE'] = CONNECTION_POOL_RECYCLE
Example #5
0
File: main.py Project: jackij/FPWeb
  )
log = logging.getLogger('neuropost')
log.info('Starting neuropost')
from flask import Flask
from database import db
from login_stuff import login_manager, oid
from urls import everything
from database import MYSQL_CONN
from sooper_sekrit import MYSQL_CONN_INFO, sekrit


TESTING = True


app = Flask(__name__)
app.secret_key = sekrit
app.config['SQLALCHEMY_DATABASE_URI'] = MYSQL_CONN % MYSQL_CONN_INFO
#app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
app.config['SQLALCHEMY_POOL_RECYCLE'] = 60 * 60 # Once an hour.
app.debug = TESTING

db.init_app(app)
login_manager.setup_app(app)
oid.init_app(app)


for urls in everything:
  log.info('Mapping URLs')
  urls(app)
  log.info('Mapping URLs finished.')
Example #6
0

app = Flask(__name__,
            static_url_path='%s/static' % config.get('url', 'base'),
            static_folder='static')


# Database connection
# ----------------------------------------------------------------------------
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://%s:%s@%s:3306/%s' % (
    config.get('db', 'user'),
    config.get('db', 'passwd'),
    config.get('db', 'host'),
    config.get('db', 'db')
)
app.config['SQLALCHEMY_POOL_RECYCLE'] = 1800 # Recycle every 30 min.
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy()
db.init_app(app)

app.config.base_tag_url = '/'


# Server endpoints
# ----------------------------------------------------------------------------
from slate import endpoints
app.register_blueprint(endpoints.account)
app.register_blueprint(endpoints.auth)
app.register_blueprint(endpoints.categories)
app.register_blueprint(endpoints.expenses)
Example #7
0
from config import DBPASS
from config import DBHOST
from config import DBNAME
from config import SCHEMA
from medline_journal import MedlineJournal
from pubmed import FetchMedline
from pubmed import Pubmed

app = Flask(__name__)

## http://packages.python.org/Flask-SQLAlchemy/config.html
## how to adjust these parameters to make sure it won't timeout??
app.config['SQLALCHEMY_DATABASE_URI'] = "%s://%s:%s@%s/%s" % (DBTYPE, DBUSER, DBPASS, DBHOST, DBNAME)
app.config['SQLALCHEMY_POOL_SIZE'] = 10 ## default = 5 
app.config['SQLALCHEMY_POOL_TIMEOUT'] = 50 ## default = 10
app.config['SQLALCHEMY_POOL_RECYCLE'] = 1800 # 30min

db = SQLAlchemy(app)
meta =  db.MetaData(bind=db.engine)

class Database():

    def __init__(self, user, password):
#        db.seesion.dispose()
#        db.session.recreate()
        app.config['SQLALCHEMY_DATABASE_URI'] = "%s://%s:%s@%s/%s" % (DBTYPE, user, password, DBHOST, DBNAME)
        db = SQLAlchemy(app)
        # db.init_app(app)
        meta = db.MetaData(bind=db.engine)
        
    @classmethod