def setUpClass(cls): cls.connection = r.connect(host=DB.RDB_HOST, port=DB.RDB_PORT, db=DB_AWS_TEST) try: # Create the DB tables we need DB.Database.create_db_structure(DB_AWS_TEST) test_conf = TestingConfig(DB_AWS_TEST) cls.app = app.create_app(test_conf).test_client() # print 'Set-up DONE. DB-name: {db_name}'.format(db_name=DB_AWS_TEST) except RqlRuntimeError: # print 'The test-database already exist. Will remove it, and then re-run the test!' r.db_drop(DB_AWS_TEST).run(cls.connection) cls.setUpClass()
def app(request): """Session-wide test `Flask` application.""" app = create_app(config.TestingConfig) # Establish an application context before running the tests. ctx = app.app_context() ctx.push() def teardown(): ctx.pop() request.addfinalizer(teardown) mixer.init_app(app) return app
from website.app import create_app app = create_app({ 'SECRET_KEY': 'secret', 'OAUTH2_REFRESH_TOKEN_GENERATOR': True, 'SQLALCHEMY_TRACK_MODIFICATIONS': False, 'SQLALCHEMY_DATABASE_URI': 'sqlite:///db.sqlite', }) @app.cli.command() def initdb(): from website.models import db db.create_all() # by shilei 2019-01-16 23:57 begin # You can run flask in PyCharm import os os.environ["AUTHLIB_INSECURE_TRANSPORT"] = "1" app.run() # by shilei 2019-01-16 23:57 end
from website.app import create_app application = create_app({ 'SECRET_KEY': 'secret', }) if __name__ == '__main__': application.run(host="127.0.0.1", port=5000, debug=True)
from website.app import create_app app = create_app({ 'SECRET_KEY': 'secret', 'OAUTH2_REFRESH_TOKEN_GENERATOR': True, 'SQLALCHEMY_TRACK_MODIFICATIONS': True, 'SQLALCHEMY_DATABASE_URI': 'mysql+pymysql://root:root@localhost/oauth?charset=utf8', # 'SQLALCHEMY_DATABASE_URI': 'sqlite:///db.sqlite', }) def initdb(): from website.models import db db.create_all()
from website.app import create_app import website.config as config import os config_object = eval(os.environ['FLASK_APP_CONFIG']) app = create_app(config_object) if __name__ == "__main__": app.run()
from website.app import create_app app = create_app({ 'SECRET_KEY': 'secret', 'OAUTH2_REFRESH_TOKEN_GENERATOR': True, 'SQLALCHEMY_TRACK_MODIFICATIONS': False, 'SQLALCHEMY_DATABASE_URI': 'sqlite:///db.sqlite', }) @app.cli.command() def initdb(): from website.models import db db.create_all()
from flask_script import Server from website.extensions import manager, db from website.app import create_app # Set the path import os import sys sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) _app = create_app() manager.app = _app db.app = _app # Turn on debugger by default and reloader manager.add_command("run", Server( use_debugger=True, use_reloader=True, host=os.getenv('IP', '0.0.0.0'), port=int(os.getenv('PORT', 5000)) )) if __name__ == "__main__": manager.run()
from website.app import create_app app = create_app('development') if __name__ == '__main__': app.run(host='0.0.0.0', port=80)
GRANT_TYPES_EXPIRES_IN = { 'authorization_code': 864000, 'implicit': 3600, 'password': 864000, 'client_credentials': 864000 } """ app = create_app({ 'SECRET_KEY': 'secret', 'OAUTH2_TOKEN_EXPIRES_IN': { 'authorization_code': 120 }, 'OAUTH2_ACCESS_TOKEN_GENERATOR': True, 'OAUTH2_REFRESH_TOKEN_GENERATOR': True, 'SQLALCHEMY_TRACK_MODIFICATIONS': True, # 'SQLALCHEMY_DATABASE_URI': 'sqlite:///db.sqlite', 'SQLALCHEMY_DATABASE_URI': 'mysql+pymysql://root:[email protected]:3306/oauth2?charset=utf8mb4' }) @app.errorhandler(404) def miss(e): """ 404、405错误仅会被全局错误处理函数捕捉,如区分蓝本URL下的404和405错误, 在全局定义的404错误处理函数中使用request.path.startswith('<蓝本的URL前缀>') 来判断请求的URL是否属于某个蓝本。
from website.app import create_app app = create_app('config.py')
from website.app import create_app app = create_app({ 'SECRET_KEY': 'secret', }) app.run()
print p own_plants[p['id']] = AutomaticWateringSystem(uuid=p['id'], name=p[Database.TABLE_OWN_PLANT_NAME], temperature_pin=p[Database.TABLE_OWN_PLANT_TEMPERATURE_PIN], magnetic_valve_pin=p[Database.TABLE_OWN_PLANT_MAGNETIC_VALVE_PIN], moisture_pin=p[Database.TABLE_OWN_PLANT_MOISTURE_PIN], gpio_debug=False, debug=True) ValveQueue = WateringQueue(True) reload_flask = False # if environ.get('RELOAD_FLASK') is not None: # reload_flask = True app = app.create_app(DevelopmentConfig) app.run(host='0.0.0.0', use_reloader=reload_flask) for a in own_plants: a.cleanup() print 'CLEEEEEANUP' # gpio.digitalWrite(pump_pin, gpio.LOW) # gpio.cleanup() # # # NOTE: There will exist one class PER temperature sensor # # temperature_pin = 0 # # GetTemperature = Temperature(analogPins.get(temperature_pin), 30) # # # # # NOTE: There will exist one class PER magnetic valve # # magnetic_valve_pin = 6
import os from pathlib import Path from dotenv import load_dotenv load_dotenv() app = create_app({ 'SECRET_KEY': os.getenv('SECRET_KEY'), 'OAUTH2_REFRESH_TOKEN_GENERATOR': os.getenv('OAUTH2_REFRESH_TOKEN_GENERATOR') == "1", 'OAUTH2_JWT_ENABLED': os.getenv('OAUTH2_JWT_ENABLED') == "1", 'OAUTH2_JWT_ALG': os.getenv('OAUTH2_JWT_ALG'), 'OAUTH2_JWT_KEY_PATH': str(Path(os.getenv('OAUTH2_JWT_KEY_PATH')).resolve()), 'OAUTH2_JWT_PUBLIC_KEY_PATH': str(Path(os.getenv('OAUTH2_JWT_PUBLIC_KEY_PATH')).resolve()), 'SQLALCHEMY_TRACK_MODIFICATIONS': os.getenv('SQLALCHEMY_TRACK_MODIFICATIONS') == "1", 'OAUTH2_JWT_ISS': os.getenv('OAUTH2_JWT_ISS'), 'OAUTH2_JWT_EXP': os.getenv('OAUTH2_JWT_EXP'), 'SQLALCHEMY_DATABASE_URI': os.getenv('SQLALCHEMY_DATABASE_URI') }) def initialize_database(app): from website.models import db with app.app_context():
import re from datetime import datetime import requests import requests_cache from bs4 import BeautifulSoup as BS from boardgamegeek import BGGClient from website.models import Game, db from website.app import create_app import website.config as config config.Config.SQLALCHEMY_DATABASE_URI = 'postgresql://*****:*****@localhost:5433/gamebrowser' app = create_app(config.DevelopmentConfig) app.app_context().push() db.init_app(app) requests_cache.install_cache() def collection_from_website(username, pagenum=1): url = 'https://boardgamegeek.com/collection/user/{}?own=1&subtype=boardgame&excludesubtype=boardgameexpansion&pageID={}'.format( username, pagenum) bgg_page = requests.get(url) url_text = BS(bgg_page.content, 'html.parser') numgames_text = url_text.find('span', attrs={'class': 'geekpages'}) numgames = int( re.search('(?<=of )[0-9]{1,5}', str(numgames_text)).group(0)) game_list = games_from_html(url_text) if pagenum < ((numgames // 300) + 1): pagenum += 1 game_list.update(collection_from_website(username, pagenum)) return game_list
def test_create_app() : app = create_app(config.DevelopmentConfig) assert app is not None
import os from website.app import create_app from website.models import db basedir = os.path.abspath(os.path.dirname(__file__)) app = create_app({ 'SECRET_KEY': 'secret', 'OAUTH2_REFRESH_TOKEN_GENERATOR': True, 'SQLALCHEMY_TRACK_MODIFICATIONS': False, 'SQLALCHEMY_DATABASE_URI': 'sqlite:///' + os.path.join(basedir, 'flask_oauth2.sqlite') }) @app.cli.command() def initdb(): db.create_all() def create_app(): db.init_app(app) return app
from website.app import create_app app = create_app({ 'SECRET_KEY': 'secret', 'SQLALCHEMY_TRACK_MODIFICATIONS': False, 'SQLALCHEMY_DATABASE_URI': 'sqlite:///db.sqlite', }) @app.cli.command() def initdb(): from website.models import db db.create_all()
from website.app import create_app app = create_app({ 'SECRET_KEY': 'secret', 'OAUTH2_REFRESH_TOKEN_GENERATOR': True, 'DB': { 'provider': 'sqlite', 'filename': 'db.sqlite', 'create_db': True } })
import os from website.app import create_app os.environ.setdefault('AUTHLIB_INSECURE_TRANSPORT', '1') # use http app = create_app({ 'SECRET_KEY': 'secret', 'OAUTH2_REFRESH_TOKEN_GENERATOR': True, 'SQLALCHEMY_TRACK_MODIFICATIONS': False, 'SQLALCHEMY_DATABASE_URI': 'mysql+pymysql://root:12345678@localhost:3306/test', }) @app.cli.command() def initdb(): from website.models import db db.create_all() if __name__ == '__main__': app.run('127.0.0.1', port=5000, debug=True)
from website.app import create_app import os from dotenv import load_dotenv # load .env dotenv_path = os.path.join(os.path.dirname(__file__), '.flaskenv') if os.path.exists(dotenv_path): load_dotenv(dotenv_path, override=True) app = create_app(os.getenv('FLASK_ENV')) if __name__ == "__main__": app.run()