
from __future__ import absolute_import, unicode_literals


from flask import Flask

from .middleware.me import me
from .cache import cache


def _register_module(app, module):
    if module == 'douban':
        from .middleware import douban
        app.register_blueprint(douban.douban_api)
    elif module == 'github':
        from .middleware import github
        app.register_blueprint(github.github_api)
    elif module == 'instagram':
        from .middleware import instagram
        app.register_blueprint(instagram.instagram_api)
    elif module == 'keybase':
        from .middleware import keybase
        app.register_blueprint(keybase.keybase_api)
    elif module == 'medium':
        from .middleware import medium
        app.register_blueprint(medium.medium_api)
    elif module == 'stackoverflow':
        from .middleware import stackoverflow
        app.register_blueprint(stackoverflow.stackoverflow_api)


def create_app(config):
    app = Flask(__name__)
    app.config.from_object(config)
    cache.init_app(app)

    modules = config.modules['modules']
    app.register_blueprint(me)
    for module in modules.keys():
        _register_module(app, module)

    return app


from __future__ import absolute_import, unicode_literals


from flask import Flask
from werkzeug.utils import import_string

from me_api.middleware.me import me
from me_api.cache import cache


middlewares = {
    'douban': 'me_api.middleware.douban:douban_api',
    'github': 'me_api.middleware.github:github_api',
    'instagram': 'me_api.middleware.instagram:instagram_api',
    'keybase': 'me_api.middleware.keybase:keybase_api',
    'medium': 'me_api.middleware.medium:medium_api',
    'stackoverflow': 'me_api.middleware.stackoverflow:stackoverflow_api',
}


def create_app(config):
    app = Flask(__name__)
    app.config.from_object(config)
    cache.init_app(app)

    modules = config.modules['modules']
    app.register_blueprint(me)
    for module in modules.keys():
        blueprint = import_string(middlewares[module])
        app.register_blueprint(blueprint)

    return app

Improve the way that import middlewares
Improve the way that import middlewares

  
  from __future__ import absolute_import, unicode_literals
  
  
  from flask import Flask
+ from werkzeug.utils import import_string
  
- from .middleware.me import me
+ from me_api.middleware.me import me
- from .cache import cache
+ from me_api.cache import cache
  
  
+ middlewares = {
+     'douban': 'me_api.middleware.douban:douban_api',
+     'github': 'me_api.middleware.github:github_api',
+     'instagram': 'me_api.middleware.instagram:instagram_api',
+     'keybase': 'me_api.middleware.keybase:keybase_api',
+     'medium': 'me_api.middleware.medium:medium_api',
+     'stackoverflow': 'me_api.middleware.stackoverflow:stackoverflow_api',
+ }
- def _register_module(app, module):
-     if module == 'douban':
-         from .middleware import douban
-         app.register_blueprint(douban.douban_api)
-     elif module == 'github':
-         from .middleware import github
-         app.register_blueprint(github.github_api)
-     elif module == 'instagram':
-         from .middleware import instagram
-         app.register_blueprint(instagram.instagram_api)
-     elif module == 'keybase':
-         from .middleware import keybase
-         app.register_blueprint(keybase.keybase_api)
-     elif module == 'medium':
-         from .middleware import medium
-         app.register_blueprint(medium.medium_api)
-     elif module == 'stackoverflow':
-         from .middleware import stackoverflow
-         app.register_blueprint(stackoverflow.stackoverflow_api)
  
  
  def create_app(config):
      app = Flask(__name__)
      app.config.from_object(config)
      cache.init_app(app)
  
      modules = config.modules['modules']
      app.register_blueprint(me)
      for module in modules.keys():
-         _register_module(app, module)
+         blueprint = import_string(middlewares[module])
+         app.register_blueprint(blueprint)
  
      return app
  
Improve the way that import middlewares
## Code Before:

from __future__ import absolute_import, unicode_literals


from flask import Flask

from .middleware.me import me
from .cache import cache


def _register_module(app, module):
    if module == 'douban':
        from .middleware import douban
        app.register_blueprint(douban.douban_api)
    elif module == 'github':
        from .middleware import github
        app.register_blueprint(github.github_api)
    elif module == 'instagram':
        from .middleware import instagram
        app.register_blueprint(instagram.instagram_api)
    elif module == 'keybase':
        from .middleware import keybase
        app.register_blueprint(keybase.keybase_api)
    elif module == 'medium':
        from .middleware import medium
        app.register_blueprint(medium.medium_api)
    elif module == 'stackoverflow':
        from .middleware import stackoverflow
        app.register_blueprint(stackoverflow.stackoverflow_api)


def create_app(config):
    app = Flask(__name__)
    app.config.from_object(config)
    cache.init_app(app)

    modules = config.modules['modules']
    app.register_blueprint(me)
    for module in modules.keys():
        _register_module(app, module)

    return app

## Instruction:
Improve the way that import middlewares
## Code After:

from __future__ import absolute_import, unicode_literals


from flask import Flask
from werkzeug.utils import import_string

from me_api.middleware.me import me
from me_api.cache import cache


middlewares = {
    'douban': 'me_api.middleware.douban:douban_api',
    'github': 'me_api.middleware.github:github_api',
    'instagram': 'me_api.middleware.instagram:instagram_api',
    'keybase': 'me_api.middleware.keybase:keybase_api',
    'medium': 'me_api.middleware.medium:medium_api',
    'stackoverflow': 'me_api.middleware.stackoverflow:stackoverflow_api',
}


def create_app(config):
    app = Flask(__name__)
    app.config.from_object(config)
    cache.init_app(app)

    modules = config.modules['modules']
    app.register_blueprint(me)
    for module in modules.keys():
        blueprint = import_string(middlewares[module])
        app.register_blueprint(blueprint)

    return app
