# Path: app.py



import os
import sys
import time
import gevent
from flask import request, Response
from gevent.wsgi import WSGIServer
from gevent.queue import Queue
from app import app

sys.path.insert(0, os.path.dirname(os.path.abspath(os.path.dirname(__file__))))




# SSE "protocol" is described here: http://mzl.la/UPFyxY
class ServerSentEvent(object):
    
    def __init__(self, data):
        self.data = data
        self.event = None
        self.id = None
        self.desc_map = {
            self.data: "data",
            self.event: "event",
            self.id: "id"
        }

    def encode(self):
        if not self.data:
            return ""
        lines = ["%s: %s" % (v, k) for k, v in self.desc_map.iteritems() if k]
        return "%s\n\n" % "\n".join(lines)


subscriptions = []


# Client code consumes like this.

# Path: app.py



# Path: javascript/realtime_using_sse.py
import os
import sys
import time
import gevent
from flask import request, Response
from gevent.wsgi import WSGIServer
from gevent.queue import Queue
from app import app


sys.path.insert(0, os.path.dirname(os.path.abspath(os.path.dirname(__file__))))




# SSE "protocol" is described here: http://mzl.la/UPFyxY
class ServerSentEvent(object):
    
    def __init__(self, data):
        self.data = data
        self.event = None
        self.id = None
        self.desc_map = {
            self.data: "data",
            self.event: "event",
            self.id: "id"
        }

    def encode(self):
        if not self.data:
            return ""
        lines = ["%s: %s" % (v, k) for k, v in self.desc_map.iteritems() if k]
        return "%s\n\n" % "\n".join(lines)


subscriptions = []


# Client code consumes like this.

@app.route('/')