Example #1
0
def create_app(package_name, package_path, settings_override=None,
               register_security_blueprint=True, config_name="development"):
    """Returns a :class:`Flask` application instance configured with common
    functionality for the chatfirst platform.
    :param package_name: application package name
    :param package_path: application package path
    :param settings_override: a dictionary of settings to override
    :param register_security_blueprint: flag to specify if the Flask-Security
                                        Blueprint should be registered. Defaults
                                        to `True`.
    """
    app = Flask(package_name, instance_relative_config=True)

    app.config.from_object('webpanda.settings')
    app.config.from_object(config[config_name])
    app.config.from_pyfile('settings.cfg', silent=True)
    app.config.from_object(settings_override)
    if 'SQLALCHEMY_DATABASE_URI' in os.environ.keys():
        app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL']

    db.init_app(app)
    #security.init_app(app, SQLAlchemyUserDatastore(db, User, Role),
    #                  register_blueprint=register_security_blueprint)

    register_blueprints(app, package_name, package_path)

    app.wsgi_app = HTTPMethodOverrideMiddleware(app.wsgi_app)

    app.log = NrckiLogger().getLogger(package_name)

    # Prepare auth
    lm.init_app(app)
    lm.login_view = 'auth.main_auth'

    lm.anonymous_user = AnonymousUser

    @lm.user_loader
    def load_user(id):
        if id == 0:
            return AnonymousUser()
        return users_.get(id=id)

    @app.before_request
    def before_request():
        g.user = current_user
        g.user.last_seen = datetime.utcnow()
        g.user.save()

        values = request.form.to_dict()
        app.log.info("incoming request: {method} {url}; Form: {form}; Data: {data}".format(method=request.method,
                                                                                       url=request.full_path,
                                                                                       form=str(values), data=str(
                request.get_json(silent=True))))

    return app
Example #2
0
from flask import Flask, Response, request
from flask.ext.httpauth import HTTPBasicAuth
from logbook import Logger
import json
import os.path

app = Flask(__name__)
auth = HTTPBasicAuth()
app.log = Logger(__name__)

user_db = json.load(
    open(os.path.expanduser("~/.doorbot_users"), 'r')
)
config_settings = json.load(
    open(os.path.expanduser("~/.doorbot_config"), 'r')
)

@auth.get_password
def get_pw(username):
    if username in user_db:
        return user_db.get(username)
    return None

import interfaces
app.doors = {
    door_config['doorid']:interfaces.pick(
        door_config['interface']
    )(**door_config) for door_config in config_settings['doors']
}

app.log.debug("Got Doors: {} from Config {}".format(app.doors, config_settings))
Example #3
0
		req_json = request.get_json()

		if req_json is None:

			return jsonify( error = 'this service require A JSON request' )

		else:
			if not ('text' in req_json):
				raise Exception('Missing mandatory paramater "text"')

			text = req_json['text']
			blob = TextBlob(text)
			sentiment = blob.sentiment

			return jsonify( polarity = sentiment.polarity, subjectivity = sentiment.subjectivity)

	except Exception as ex:
		app.log.error(type(ex))
		app.log.error(ex.args)
		app.log.error(ex)
		return jsonify(error = str(ex))

if __name__ == '__main__':

	LOG_FORMAT = "'%(asctime)s - %(name)s - %(levelname)s - %(message)s'"
  	logging.basicConfig(level=logging.DEBUG,format=LOG_FORMAT)
	app.log = logging.getLogger(__name__)

	port = os.environ['FLASK_PORT']
	app.run(host='0.0.0.0',port=int(port),debug=False)
Example #4
0
from flask import jsonify, redirect, url_for, escape
from flask import request, session
from flask import g as Globals
from flask.ext.socketio import SocketIO, emit, join_room, leave_room
import logging

logging.basicConfig()

app = Flask(__name__)
# app.config['SECRET_KEY'] = 'secret!'
app.secret_key = "A0Zr98j/3yX R~XHH!jmN]LWX/,?RT"

socketio = SocketIO(app)

app.artist = 0
app.log = {}


@app.route("/<path:path>")
def static_proxy(path):
    return app.send_static_file(path)


@app.route("/draw/<room>")
def drawing_room(room):
    session["artist"] = str(app.artist)
    session["room"] = room
    app.artist += 1

    return app.send_static_file("draw.html")