Ejemplo n.º 1
0
class Mate:
    def __init__(self):
        pass

    def set_keyword(self, k):
        self.keyword = k


mate = Mate()

# app setup

app = Flask(__name__)
app.config['SECRET_KEY'] = ''
socketio = SocketIO(app)


@app.route('/noisytweets')
def index():
    return render_template('index.html')


# socket setup


@socketio.on('connect', namespace='/noisytweets')
def test_connect():
    socketio.emit('connect okay', {'data': 'Connected'},
                  namespace='/noisytweets')
Ejemplo n.º 2
0
A simple web dashboard for examining the state of a game engine.

"""
from flask import Flask, jsonify, redirect, request, render_template, url_for, send_from_directory, json
from flask.ext.socketio import SocketIO, emit
import json
import urllib

# Set this variable to "threading", "eventlet" or "gevent" to test the
# different async modes, or leave it set to None for the application to choose
# the best option based on installed packages.
async_mode = None

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app, async_mode=async_mode)
thread = None
engine_url = "http://*****:*****@app.route("/")
def index(name=None):
Ejemplo n.º 3
0
        if m in service_list:
            port = service_list[m].port
        elif m.isdigit():
            port = int(m)
        else:
            print("service not found")
            exit(-1)
        sock = messaging.sub_sock(context, port, poller, addr=args.addr)
        if args.proxy:
            republish_socks[sock] = messaging.pub_sock(context, port)

    if args.map:
        from flask.ext.socketio import SocketIO  #pylint: disable=no-name-in-module, import-error
        from flask import Flask
        app = Flask(__name__)
        socketio = SocketIO(app, async_mode='threading')
        server_thread = Thread(target=run_server, args=(socketio, ))
        server_thread.daemon = True
        server_thread.start()
        print 'server running'

    while 1:
        polld = poller.poll(timeout=1000)
        for sock, mode in polld:
            if mode != zmq.POLLIN:
                continue
            msg = sock.recv()
            evt = log.Event.from_bytes(msg)
            if sock in republish_socks:
                republish_socks[sock].send(msg)
            if args.map and evt.which() == 'liveLocation':
Ejemplo n.º 4
0
import eventlet
eventlet.monkey_patch()
from flask.ext.socketio import SocketIO, emit
from flask import Flask, render_template, url_for, copy_current_request_context, request
from random import random
from time import sleep
from threading import Thread, Event

__author__ = 'aba'

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
app.config['DEBUG'] = True

#turn the flask app into a socketio app
socketio = SocketIO(app, async_mode='eventlet', engineio_logger=True)

#random number Generator Thread
thread = Thread()
thread_stop_event = Event()


class RandomThread(Thread):
    def __init__(self, maxn):
        self.delay = 1.0
        self.max = maxn
        super(RandomThread, self).__init__()

    def randomNumberGenerator(self):
        """
        Generate a random number every 1 second and emit to a socketio instance (broadcast)
Ejemplo n.º 5
0
from flask import Flask, render_template
from flask.ext.socketio import SocketIO, emit
from datetime import datetime
import os

app = Flask(__name__)
app.config.from_pyfile('config.py')
ws = SocketIO(app)

last_messages = []


@app.route('/')
def hello_world():
    return render_template('index.html')


@ws.on('connect', namespace='/chat')
def connect():
    for x in last_messages:
        emit('message', x)


@ws.on('joined_message', namespace='/chat')
def joined_chat(data):
    emit('message', {
        'username': data['username'],
        'dateTime': datetime.utcnow().isoformat() + 'Z',
        'type': 'joined_message'
    },
         namespace='/chat',
Ejemplo n.º 6
0
import zmq.green as zmq
from subprocess import Popen, PIPE, STDOUT
import logging
import coloredlogs
from datetime import datetime

from flask import Flask, render_template
from flask import send_from_directory
from flask.ext.socketio import SocketIO, emit

logger = logging.getLogger('flask-app')

web = Flask(__name__)
web.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(web)

zmq_context = zmq.Context()


def parse_monitor(raw):
    topic, binary, _, msg = raw
    data = json.loads(msg)
    return {
        'topic': topic,
        'data': data
    }


@web.route('/')
def index():
Ejemplo n.º 7
0
from database import db
from database.chosen_words import ChosenWords
from database.user_connections import UserConnections

app = Flask(__name__)
app.config['SECRET_KEY'] = 'PolarBearSunset'

# Init the database
# TMP db is fine for now
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
db.init_app(app)
with app.app_context():
    db.create_all()

# Init the socket and the vote manager class
socket = SocketIO(app)
vote_manager = VoteManager(app, socket)


def log_connect(user_id):
    connection = UserConnections('connect', time.time(), user_id)
    db.session.add(connection)
    db.session.commit()


@app.route('/')
def index():
    """
    Serves up our client to the user.
    """
    # Give the user a session cookie so their vote
Ejemplo n.º 8
0
from flask import Flask
from flask.ext.login import LoginManager
from flask.ext.bootstrap import Bootstrap
from flask.ext.socketio import SocketIO
from config import config
from .model import db

login_manager = LoginManager()
login_manager.session_protection = 'strong'
login_manager.login_view = 'main.login'
bootstrap = Bootstrap()
socketio = SocketIO()


def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])

    db.init_app(app)
    login_manager.init_app(app)
    bootstrap.init_app(app)
    socketio.init_app(app)

    register_app_blueprints(app)

    return app, socketio


def register_app_blueprints(app):
    from viewer.main import main as main_blueprint
    app.register_blueprint(main_blueprint)