Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8712569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:08:18+00:00 2026-06-13T05:08:18+00:00

I’m trying to return to the client a stream of twitter metadata which the

  • 0

I’m trying to return to the client a stream of twitter metadata which the client enters in a form filtered by tweepy’s ‘track’.

The problem I’m having is that nothing is returned back to the browser, eventhough the server receives it and processes the request. This is my code so far:

The main.py:

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


app = flask.Flask(__name__)
app.secret_key = "asecret"

class View(MethodView):

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

def post(self):
    results = StreamerRt().filter(track = (flask.request.form['event']))
    flask.flash(results)
    return self.get()

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

The class connecting to the Twitter Streaming API:

import sys
import tweepy
import json
import time
#from textwrap import TextWrapper
import pymongo

CONSUMER_KEY = ''
CONSUMER_SECRET = ''

ACCESS_TOKEN = ''
ACCESS_TOKEN_SECRET = ''

auth = tweepy.OAuthHandler(CONSUMER_KEY,CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN,ACCESS_TOKEN_SECRET)


connection = pymongo.Connection()  
db = connection.twitterStream

class Listener(tweepy.StreamListener):


    def on_status(self, status):
        message = {}

        if status.author.lang == 'en':
            try:
                message = {
                           'Author': status.author.screen_name,
                           'Author_id': status.id,
                           'Time_normal': str(status.created_at),
                           'geo_enabled': status.author.geo_enabled,
                           'Geo': status.geo,
                           'Place' : status.place,
                           'Coordinates': status.coordinates}

                db.tweetStream.insert(message)


            except Exception, e:
                print >> sys.stderr, 'Encountered Exception:', e
                pass

        def on_error(self, status_code):

            waitPeriod = 60
            if status_code == 420:
                print >> sys.stderr, 'Encountered a %i Error, will retry in %i minutes'     % \
                (status_code, waitPeriod/60)
                time.sleep(waitPeriod)
                waitPeriod *= 2
                return waitPeriod
            else:            
                print >> sys.stderr, 'Encountered error with status code:', status_code
                return True 

        def on_timeout(self):
            print >> sys.stderr, 'Timeout...'
            return True 

def StreamerRt():
    return tweepy.streaming.Stream(auth, Listener(), timeout=60)

My html file which inherits from a base and forms html file:

{% 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>
        {% with messages = get_flashed_messages() %}
    {% if messages %}
                Results:
                <pre>
                    {% for message in messages %}
{{ message }}
                    {% endfor %}
                  </pre>
               {% endif %}
             {% endwith %}        
           {% endblock %}

It seems that I can’t return any streaming data to the client.

How could you return certain metadata from Twitter Streaming API to the browser, at the same time that it is written into the DB.

Thanks

Furthermore the function StreamerRt doesnt filter by track as input from the client, but seems to return the whole public timeline.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:08:19+00:00Added an answer on June 13, 2026 at 5:08 am

    I think Flask-Sijax is what you are looking for. Hookbox is another option, here is a tutorial on how to integrate hookbox with flask. Yet another option is gevent here is a SO post on using gevent with flask. Last one I can think of is tornado.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to select an H1 element which is the second-child in its group
I have a text area in my form which accepts all possible characters from
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.