text: from flask import Flask, request
  from config import Config
  from flask_sqlalchemy import SQLAlchemy
  from flask_migrate import Migrate
  from flask_login import LoginManager
  import logging
  from logging.handlers import SMTPHandler, RotatingFileHandler
  import os
  from flask_mail import Mail
  from flask_bootstrap import Bootstrap
  from flask_moment import Moment
  from flask_babel import Babel, lazy_gettext as _l, _
  from dotenv import load_dotenv
  from elasticsearch import Elasticsearch
  from flask_bootstrap import Bootstrap
  from flask_admin import Admin
  
  
  load_dotenv()
  
  app = Flask(__name__)
  app.config.from_object(Config)
  db = SQLAlchemy(app)
  migrate = Migrate(app, db)
  login = LoginManager(app)
  login.login_view = 'login'
  login.login_message = _l('Please log in to access this page.')
  app.elasticsearch = Elasticsearch([os.getenv("ELASTICSEARCH_URL")]) \
          if os.getenv("ELASTICSEARCH_URL") else None 
  bootstrap = Bootstrap(app)
  
  
  os.getenv("MS_TRANSLATOR_KEY")
  os.getenv("MAIL_SERVER")
  os.getenv("MAIL_PORT")
  os.getenv("MAIL_USERNAME")
  os.getenv("MAIL_PASSWORD")
  
  app.config['FLASK_ADMIN_SWATCH'] = 'cosmo'
  
  
  mail = Mail(app)
  moment = Moment(app)
  babel = Babel(app)
  
  from app import routes, models, errors
  
  if not app.debug:
      if app.config['MAIL_SERVER']:
          auth = None
          if app.config['MAIL_USERNAME'] or app.config['MAIL_PASSWORD']:
              auth = (app.config['MAIL_USERNAME'], app.config['MAIL_PASSWORD'])
          secure = None
          if app.config['MAIL_USE_TLS']:
              secure = ()
          mail_handler = SMTPHandler(
              mailhost=(app.config['MAIL_SERVER'], app.config['MAIL_PORT']),
              fromaddr='no-reply@' + app.config['MAIL_SERVER'],
              toaddrs=app.config['ADMINS'], subject='Microblog Failure',
              credentials=auth, secure=secure)
          mail_handler.setLevel(logging.ERROR)
          app.logger.addHandler(mail_handler)
      if not os.path.exists('logs'):
          os.mkdir('logs')
      file_handler = RotatingFileHandler('logs/microblog.log', maxBytes=10240,
                                         backupCount=10)
      file_handler.setFormatter(logging.Formatter(
          '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'))
      file_handler.setLevel(logging.INFO)
      app.logger.addHandler(file_handler)
  
      app.logger.setLevel(logging.INFO)
      app.logger.info('Microblog startup')
  
  
  
  @babel.localeselector
  def get_locale():
      return request.accept_languages.best_match(app.config['LANGUAGES'])
  