def create_app(config_name=None): if config_name is None: # config_name = os.getenv('FLASK_CONFIG', 'development') config_name = os.getenv('FLASK_CONFIG', 'production') app = Flask(__name__) app.config.from_object(config[config_name]) app.response_class = XMLResponse # Add analytics from flask_analytics import Analytics from rsshub.google_analytics import ga_account Analytics(app) app.config['ANALYTICS']['GOOGLE_UNIVERSAL_ANALYTICS'][ 'ACCOUNT'] = ga_account app.config['ANALYTICS']['ENABLED'] = True register_blueprints(app) register_extensions(app) register_errors(app) register_context_processors(app) register_cli(app) return app
def create_app(): """Initialize the core application""" app = Flask(__name__) app.config.from_object(os.environ['APP_SETTINGS']) with app.app_context(): Analytics(app) Compress(app) SSLify(app, skips=["webhook_callback"]) from .js_bundles import bundles assets.register(bundles) for bundle in bundles.values(): bundle.build() db_sql.init_app(app) redis.init_app(app) mongo.init_app(app, **app.config["MONGO_OPTIONS"]) login_manager.init_app(app) sockets.init_app(app) assets.init_app(app) limiter.init_app(app) # talisman.init_app( # app, # content_security_policy=app.config["CONTENT_SECURITY_POLICY"] # ) from .models import (Activities, EventLogger, Index, Payments) import heatflask.routes # initialize/update data-stores db_sql.create_all() mongodb = mongo.db collections = mongodb.collection_names() if EventLogger.name not in collections: EventLogger.init_db() if Activities.name not in collections: Activities.init_db() else: Activities.update_ttl() if Index.name not in collections: Index.init_db() else: Index.update_ttl() if Payments.name not in collections: Payments.init_db() if app.debug: app.wsgi_app = DebuggedApplication(app.wsgi_app, evalex=True) return app
def setup_analytics(application): # Setup analytics from flask_analytics import Analytics from app.analytics.custom_google_analytics import CustomGoogleAnalytics Analytics.provider_map['google_analytics'] = CustomGoogleAnalytics Analytics(application) application.config['ANALYTICS'][ 'GOOGLE_ANALYTICS']['ACCOUNT'] = settings.EQ_UA_ID
def init(): global analytics if app.config['ANALYTICS_PIWIK_BASE_URL']: app.config['ANALYTICS'] = {} app.config['ANALYTICS']['PIWIK'] = {} app.config['ANALYTICS']['PIWIK']['BASE_URL'] = app.config[ 'ANALYTICS_PIWIK_BASE_URL'] app.config['ANALYTICS']['PIWIK']['SITE_ID'] = app.config[ 'ANALYTICS_PIWIK_SITE_ID'] analytics = Analytics(app)
def configure(app): if app.config.get('ANALYTICS_ENABLED'): Analytics(app) app.config['ANALYTICS']['GOOGLE_CLASSIC_ANALYTICS'][ 'ACCOUNT'] = app.config.get( # noqa 'ANALYTICS_SITE_ID')
EventLogger.init() if Activities.name not in collections: Activities.init_db() else: Activities.update_ttl() if Index.name not in collections: Index.init_db() else: Index.update_ttl() if Payments.name not in collections: Payments.init_db() Analytics(app) def parseInt(s): try: return int(s) except ValueError: return # we bundle javascript and css dependencies to reduce client-side overhead # app.config["CLOSURE_COMPRESSOR_OPTIMIZATION"] = "WHITESPACE_ONLY" bundles = { "dependencies_css": flask_assets.Bundle('css/main.css', 'css/jquery-ui.css',
def create_app(config="app.config"): app = Flask(__name__) with app.app_context(): app.config.from_object(config) app.jinja_loader = BlogthemeLoader(os.path.join( app.root_path, app.template_folder), followlinks=True) from app.models import db, Users url = make_url(app.config['SQLALCHEMY_DATABASE_URI']) if url.drivername == 'postgres': url.drivername = 'postgresql' db.init_app(app) try: if not (url.drivername.startswith('sqlite') or database_exists(url)): create_database(url) db.create_all() except OperationalError: db.create_all() else: db.create_all() app.db = db cache.init_app(app) app.cache = cache app.debug = False configure_uploads(app, photos) redis_store = FlaskRedis() redis_store.init_app(app) login_manager = LoginManager() login_manager.session_protection = 'strong' login_manager.login_view = 'auth.oauth' login_manager.init_app(app) toolbar = DebugToolbarExtension(app) #toolbar.DEBUG_TB_INTERCEPT_REDIRECTS = False md = Misaka() md.init_app(app) Analytics(app) app.config['ANALYTICS']['GAUGES']['SITE_ID'] = 'XXXXXXXXXXXXX' if not get_config('blog_theme'): set_config('blog_theme', 'blog') from app.views import views from app.utils import init_errors, init_utils, init_logs from app.post import blog from app.auth import auth from app.admin import admin from app.status import web #from app.api import init_errors(app) init_utils(app) init_logs(app) app.register_blueprint(views) app.register_blueprint(blog) app.register_blueprint(auth) app.register_blueprint(admin) app.register_blueprint(web) @login_manager.user_loader def load_user(user_id): try: return Users.query.get(int(user_id)) except Users.DoesNotExist: return None return app
from flask import Flask, render_template from flask_analytics import Analytics app = Flask(__name__) analytics = Analytics(app) @app.route('/') def index(): app.config['ANALYTICS'] = { 'GAUGES': { 'SITE_ID': 'soV5eile3aiFi9E' }, 'GOOGLE_CLASSIC_ANALYTICS': { 'ACCOUNT': 'wiengech9tiefuW', }, 'PIWIK': { 'BASE_URL': 'aeniki8pheiFiad', 'SITE_ID': 'uiP3eeKie6ohDo6', }, 'GOSQUARED': { 'UID': 'ahz1Nahqueorahw' }, 'CHARTBEAT': { 'UID': 'uiP3eeKie6ohDo6', 'DOMAIN': 'eeda8Otheefu5qu' }, 'GOOGLE_UNIVERSAL_ANALYTICS':{ 'ACCOUNT': 'iqmbak3kfpdg2N'