Send real time data to client with juggernaut

2019-05-09 23:42发布

问题:

I have tried to use the juggernaut framework for flask in order to send real-time information to the client browser followinf the flask snippet at http://flask.pocoo.org/snippets/80/.

When I try to implement it for my code, it still does not provide a real-time output in the client browser.

This is my python code:

import flask
from flask.views import MethodView
from tweetStreamsRT import StreamerRt 
from juggernaut import Juggernaut


app = flask.Flask(__name__)
app.secret_key = "xxxxx"
PORT = 8080

class View(MethodView):

    def get(self):
        return flask.render_template('index.html')

    def post(self):
        results = StreamerRt().filter(track=[flask.request.form['event']])            
        jug = Juggernaut()
        jug.publish('channel', results)
        return self.get()


app.add_url_rule('/', view_func = View.as_view('index'), methods=['GET', 'POST'])
app.debug = True

if __name__ == "__main__":
    print 'Listening on http://localhost:%s' % PORT
    app.run()

My html page is, which inherits from a base html page:

{% extends "base.html" %}
{% import "forms.html" as forms %}


{% block page_header %}
  <div class="page-header">
    <h1>Welcome</h1>
  </div>
{% endblock %}
{% block content %}
  <h2>Enter the Event you would like to follow</h2>
      <form action="/" method="post">
            <input type="text" name="event" />
            <input type="submit" value="Submit Query" />
          </form>
            Results:
            <pre>
                <script type="text/javascript" charset="utf-8">
                    var jug = new Juggernaut;
                    jug.subscribe("channel", function(data){
                    alert("Got data: " + data);});
                </script>

            </pre> 
{% endblock %}

I'm confused as to why nothing is sent to the client browser.

Thanks

回答1:

Juggernout is deprecated http://blog.alexmaccaw.com/killing-a-library If you're about to build your application around it it's the right time to switch to something else. Like EventSource http://www.html5rocks.com/en/tutorials/eventsource/basics/



回答2:

As another answer states, Juggernaut has now been deprecated. I would suggest using another PUB/SUB framework like Faye.