def create_app(app_settings=None): global app if not app: config_obj = get_env_config(app_settings) app = Flask(__name__, template_folder=config_obj.TEMPLATE_DIR, static_folder=config_obj.STATIC_DIR) app.config.from_object(config_obj) bootstrap.init_app(app) mail.init_app(app) return app
def setUpClass(cls): # start the driver try: import subprocess driver_directories = ['/usr/local/bin'] os.environ.update({'PATH': ':'.join(driver_directories + [os.environ.get('PATH')])}) cls.client = webdriver.Firefox() except Exception as exc: print("your path is:\n {}".format(sys.path)) print("sys path is:\n {}".format(os.environ.get('PATH'))) print("could not load selenium webdriver", str(exc), sep='\n') if cls.client: os.environ['APP_SETTINGS'] == 'testing' or os.environ.update(APP_SETTINGS='testing') cls.config_obj = get_env_config() cls.app = get_decorated_app() cls.app_context = cls.app.test_request_context() cls.app_context.push() # suppress logging import logging logger = logging.getLogger('werkzeug') logger.setLevel("ERROR") # instead of rebuilding each time, take a snapshot of db and reload that cls.db = db_session() cls.meta_db = get_db_metadata() # need to find a way to make this work # serialize_all(DB_PICKLE_NAME, cls.meta_db) # the server url cls.host = 'localhost' cls.port = 5001 cls.server_url = 'http://{}:{}'.format(cls.host, cls.port) threading.Thread(target=lambda: cls.app.run(port=cls.port)).start()
"http://localhost:3000", "https://stem-diverse-tv.herokuapp.com/", ] } }, ) app.config.update(mail_settings) api.init_app(app) db.init_app(app) from app.utils.mail_extension import mail mail.init_app(app) return app config, port = get_env_config().values() application = create_app(config) @application.before_first_request def create_tables(): db.create_all() if __name__ == "__main__": application.run(port=port)
def setUp(self): os.environ['APP_SETTINGS'] == 'testing' or os.environ.update(APP_SETTINGS='testing') self.config_obj = get_env_config() self.db = db_session() init_db() self.meta_db = get_db_metadata()
def setUpClass(cls): os.environ['APP_SETTINGS'] == 'testing' or os.environ.update(APP_SETTINGS='testing') cls.config_obj = get_env_config() cls.meta_db = get_db_metadata() init_db(seed_data=True, rebuild=True)
""" Common tasks used throughout the controllers """ import os from PIL import Image from app.celery_creator import celery from config import get_env_config app_settings = get_env_config() thumbnail_size = 400, 300 def get_thumbnail_filename(filename): base, ext = os.path.splitext(filename) return base + '.thumbnail' + ext def save_image(file, filename, create_thumbnail=True): file.save(os.path.join(app_settings.UPLOAD_FOLDER, filename)) if create_thumbnail: make_thumbnail.delay(filename) @celery.task def make_thumbnail(filename): im = Image.open(os.path.join(app_settings.UPLOAD_FOLDER, filename)) im.thumbnail(thumbnail_size, Image.ANTIALIAS) thumbnail_filename = get_thumbnail_filename(filename) im.save(os.path.join(app_settings.UPLOAD_FOLDER, thumbnail_filename))
flash, url_for, session, send_from_directory, abort) from . import main_routes from models.sheets import Sheetmusic from models import Trade, Item from app.decorators import user_is_logged_in from app.tasks import get_thumbnail_filename from config import get_env_config app_settings = get_env_config() @main_routes.route('/') def index(): suggested_sheetmusic = set([i.sheetmusic for i in Item.query.all() if i.available]) suggested_sheetmusic = sorted(suggested_sheetmusic, key=lambda i: -1*i.id)[:4] return render_template('main.html', suggested_sheetmusic=suggested_sheetmusic) @main_routes.route('/results') def search_results(): q = request.args.get('q', None) if q: q_cleaned = q.strip().lower() results = g.db.query(Sheetmusic).filter(Sheetmusic.title.ilike('%{}%'.format(q_cleaned))).all()
jwt.init_app(app) from app.api.api_extension import api api.init_app(app) from app.api.mail_extension import mail mail.init_app(app) from app.schedulers.background_scheduler import init_schedulers init_schedulers() return app application = create_app(get_env_config()) @application.before_first_request def create_tables(): from app.database.sqlalchemy_extension import db db.create_all() if __name__ == "__main__": application.run(port=5000)
#不同的app用不同证书 if 'app' in msg: pem = config[msg['app']]['pem'] else: return 'app error' apn = APN(pem, config['dev']) return apn.send(token, payload) if __name__ == '__main__': from config import get_env_config msg = { 'app': 'test', 'data': { 'type': 'feed', 'id': 123 }, 'count': 1, 'udid': 'bf7124b455c46395d619046df2b1fe68aed9cb8c2dd6b5a9f8531exxxxxxxxxx', 'content': u'44445萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德' } config = get_env_config() if not config: print 'config error' print push(msg, config)
if len(token) < 50: return 'udid invalid' payload = Payload(msg['content'], msg['count'], data) #不同的app用不同证书 if 'app' in msg: pem = config[msg['app']]['pem'] else: return 'app error' apn = APN(pem, config['dev']) return apn.send(token, payload) if __name__ == '__main__': from config import get_env_config msg = { 'app': 'test', 'data': {'type':'feed', 'id': 123}, 'count': 1, 'udid': 'bf7124b455c46395d619046df2b1fe68aed9cb8c2dd6b5a9f8531exxxxxxxxxx', 'content':u'44445萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德萨范德' } config = get_env_config() if not config: print 'config error' print push(msg, config)
import json import random from os import path import uuid from faker import Factory from app.db import db_session, init_db from config import get_env_config from models.sheets import Sheetmusic, Genre, Instrument from models.auth import User, Address from models.items import Item, ItemImage from models.trades import Trade config_obj = get_env_config() DATA_DIRECTORY = path.join(config_obj.BASE_DIR, 'util/seed_data') def load_sheet_music(): with open(path.join(DATA_DIRECTORY, 'sheet_music.json'), 'r') as fh: data = json.load(fh) for sheet_music in data['sheet_music']: if not db_session.query(Sheetmusic).filter_by(title=sheet_music['title']).first(): instrumentation = sheet_music.pop('instrumentation', None) genres = sheet_music.pop('genre_tags', None) new_obj = Sheetmusic(**sheet_music) new_obj.parse_tags(instrumentation, Instrument, 'instrumentation') new_obj.parse_tags(genres, Genre, 'genre_tags')