Exemplo n.º 1
0
def subscribe():
    response.content_type  = 'text/event-stream'
    response.cache_control = 'no-cache'

    photo = Photo()
    photo.subscribe()

    connected = True

    # Keep connection alive no more then... (s)
    while connected:
        message = photo.pubsub.get_message()

        try:
            if message:
                yield 'data: %s\n\n' % json.dumps(message)
            else:
                yield 'data: %s\n\n' % json.dumps({'keepalive': True})
        except:
             print "disconnected"
	     connected = False

        sleep(1)

    photo.unsubscribe()
Exemplo n.º 2
0
def take_photo():
    photo = Photo()
    photo.take_photo()

    return {
            'ok': True
    }
Exemplo n.º 3
0
def subscribe():
    response.content_type = 'text/event-stream'
    response.cache_control = 'no-cache'

    photo = Photo()
    photo.subscribe()

    connected = True

    # Keep connection alive no more then... (s)
    while connected:
        message = photo.pubsub.get_message()

        try:
            if message:
                yield 'data: %s\n\n' % json.dumps(message)
            else:
                yield 'data: %s\n\n' % json.dumps({'keepalive': True})
        except:
            print "disconnected"
            connected = False

        sleep(1)

    photo.unsubscribe()
Exemplo n.º 4
0
def take_photo():
    photo = Photo()
    photo.take_photo()

    return {'ok': True}