I have a Flask app where I am running Tweepy in the background to stream all live tweets of a certain tag.
My code is as follows:
app.py
from flask import Flask, render_template, jsonify
import tweepy
from settings import TwitterSettings
app = Flask(__name__)
class MyStreamListener(tweepy.StreamListener):
def on_status(self, status):
out = f"{status.user.name} has tweeted -> {status.text}"
print(out)
@app.route("/")
def index():
# Get settings instance
settings = TwitterSettings.get_instance()
# Auths
auth = tweepy.OAuthHandler(settings.consumer_key, settings.consumer_secret,)
auth.set_access_token(
settings.access_token, settings.access_token_secret,
)
# Get API
api = tweepy.API(auth)
# Live Tweets Streaming
myStreamListener = MyStreamListener()
myStream = tweepy.Stream(auth=api.auth, listener=myStreamListener)
myStream.filter(track=["fortnite"])
return render_template("Filtering")
if __name__ == "__main__":
app.run(debug=True)
The tweets are being displayed in real-time in the console.
What I want to achieve here is to be able to display it on the browser in real-time (through an HTML page). Can someone please help to guide me in the steps to implement that ?