Example #1
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 #2
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")