예제 #1
0
파일: create.py 프로젝트: ttom921/flaskfood
def create_app():
    # iniit app
    app = Flask(__name__)
    app.config['SECRET_KEY'] = "akjskldjf"

    try:
        sockets = GeventWebSocket(app=app)
    except Exception as e:
        print("Error: flask_uwsgi_websocket, {0}".format(e))

    with app.app_context():

        # 藍圖註冊
        from api.index.Index import router_index
        from api.wsocket.Wsocket import router_websocket

        app.register_blueprint(router_index)
        sockets.register_blueprint(router_websocket,
                                   url_prefix='/{0}/ws'.format("v0.0"))
    return app
예제 #2
0
from flask_uwsgi_websocket import GeventWebSocket
import re
import subprocess

from backend.backend import *

ws = GeventWebSocket(app)


@app.route("/", methods=["GET"])
@login_required
def home():
    success = request.args.get("success", None)
    error = request.args.get("error", None)

    return render_template(
        "templates/index.html",
        user=g.user,
        success=success,
        error=error,
    )


@app.route("/debug", methods=["POST"])
def debug():
    sessionID = session.get("id", None)
    if sessionID == 1:
        code = request.form.get("code", "<h1>Safe Debug</h1>")
        return render_template_string(code)
    else:
        return "Not allowed."
예제 #3
0
from flask_uwsgi_websocket import GeventWebSocket
import gevent
from flask import copy_current_request_context

UPLOAD_FOLDER = '/tmp'
ADDR = '127.0.0.1:7192'

if 'TGU_UPLOAD' in os.environ:
    UPLOAD_FOLDER = os.environ['TGU_UPLOAD']
if 'TGU_ADDR' in os.environ:
    ADDR = os.environ['TGU_ADDR']
print 'UPLOAD_FOLDER', UPLOAD_FOLDER
print 'ADDR', ADDR

application = Flask(__name__, template_folder='.')
websocket = GeventWebSocket(application)

jobs = {}


def current_milli_time():
    return int(round(time.time() * 1000))


@websocket.route('/websocket')
def echo(ws):
    with application.request_context(ws.environ):
        job_id = int(request.args.get('job_id'))
        if job_id not in jobs:
            print "no such job", job_id
            return
예제 #4
0
api.add_resource(ImageUpload, '/image')
api.add_resource(ImageView, '/image/<image_id>')

db.init_app(app)
db.create_all(app=app)

# Leaving this here for eventual API versioning.
# app.register_blueprint(api_bp, url_prefix='/api/v%s' % API_VERSION)
app.register_blueprint(api_bp)


## patch_request wraps a websocket function, patching Flask.request
def patch_request(fn):
    def wrap(ws):
        with app.request_context(ws.environ):
            fn(ws)

    return wrap


# Setup websocket route
websocket = GeventWebSocket(app)
ws_register = patch_request(ws_register)
websocket.route('/sync')(ws_register)

if __name__ == "__main__":
    logfile = app.config['LOGFILE']
    params = {'gevent': 100, 'logto': logfile, 'reuse-port': True}
    app.run(**params)
예제 #5
0
from flask import Flask, render_template, Response, flash, redirect, request, session, abort, url_for
from flask_socketio import SocketIO
from flask_uwsgi_websocket import GeventWebSocket
from camera import VideoCamera
from flask_bootstrap import Bootstrap
import enc
import os

# @ToDo pass in error for login
# @ToDo clean up


app = Flask(__name__)
websocket = GeventWebSocket(app)
app.config['SECRET_KEY'] = os.urandom(24)
socketio = SocketIO(app)

@app.route('/')
def home():
    if not session.get('logged_in'):
        return render_template('pages/login.html')
    else:
        return render_template('pages/index.html')
 
@app.route('/login', methods=['POST'])
def do_admin_login():
	if enc.decipher(request.form['username'], request.form['password']):
		session['logged_in'] = True
		return redirect(url_for('home'))
	else:
		flash('wrong password!')
예제 #6
0
파일: run.py 프로젝트: ttom921/flaskfood
#from application import app,manager
#from application import app
#import www #引入
from flask import Flask

from flask_uwsgi_websocket import WebSocket
from flask_uwsgi_websocket import GeventWebSocket

app = Flask(__name__, instance_relative_config=True)

try:
    sockets = GeventWebSocket(app=app)
except Exception as e:
    print("Error: flask_uwsgi_websocket, {0}".format(e))

#藍圖功能,對所有的url進行藍圖功能配置
from web.controller.index import router_index
from web.controller.user.User import router_user
from web.controller.wsocket.wsocket import router_websocket
app.register_blueprint(router_index, url_prefix="/")
#app.register_blueprint(router_user,url_prefix = "/v0.0/user")
# app.register_blueprint(router_index,url_prefix='/{0}/'.format(app.config['API_VERSION']))
# app.register_blueprint(router_user,url_prefix='/{0}/user'.format(app.config['API_VERSION']))
app.logger.info("---------藍圖功能------------")
#sockets.register_blueprint(router_websocket,url_prefix='/{0}/ws'.format(app.config['API_VERSION']))
sockets.register_blueprint(router_websocket,
                           url_prefix='/{0}/ws'.format("v0.0"))
#藍圖功能,對所有的url進行藍圖功能配置

#sockets.register_blueprint(blueprint=wsocket, url_prefix='/{0}/websocket/'.format(app.config['API_VERSION']))
if __name__ == '__main__':
예제 #7
0
def create_app():
    app = Flask(__name__)
    app.config.from_mapping(
        DEBUG=True
    )

    ws = GeventWebSocket(app)

    users = {}

    print("in create applicaton")

    @app.route('/')
    def index():
        print("try to render index")
        return render_template('index.html')

    @app.route('/msg')
    def sendmsg():
        res = deepcopy(DefaultResponse)

        print("in msg")

        msg = request.args.get("cmd")

        print("get msg: " + msg)

        for id in users:
            print("send msg to " + str(id))
            users[id].send(msg)

        return jsonify(res)


    @ws.route('/websocket')
    def chat(ws):
        users[ws.id] = ws

        #for msg in backlog:
            #ws.send(msg)

        while True:
            msg = ws.receive()

            print("recv websocket msg: " + str(msg))

            #time.sleep(10)

            if msg is not None:
                #backlog.append(msg)
                for id in users:
                    if id != ws.id:
                        users[id].send(msg)


            else:
                break

        #del users[ws.id]


    return app
예제 #8
0
from flask_script import Manager
from flask_uwsgi_websocket import GeventWebSocket, WebSocket
import os

# class Application(Flask):
#     def __init__(self,import_name):
#         print("Application init--------------------")
#         print("Application init")
#         super(Application,self).__init__(import_name)
#         self.config.from_pyfile('config/base_setting.py')
#         # data=os.environ
#         # print(data)
#         # if "ops_config" in os.environ:
#         #     self.config.from_pyfile('config/%s_setting.py' % os.environ['ops_config'])
#         self.config.from_pyfile('config/%s_setting.py' % 'local')

#         db.init_app(self)

db = SQLAlchemy()
app = Flask(__name__, instance_relative_config=True)
print("application.py-------------app={0}".format(id(app)))
#app = Application(__name__)

try:
    sockets = GeventWebSocket(app=app)
except Exception as e:
    print("Error: flask_uwsgi_websocket, {0}".format(e))

#manager = Manager(app)
#ockets = WebSocket(app)