![]() |
VOOZH | about |
This is a web app made using Python and Flask Framework. It has a registration system and a dashboard. Users can enter keywords to fetch live tweets from Twitter and analyze them for sentiment. The results are then visualized in a graph. The project uses the popular Tweepy API to connect to X (formerly twitter) in real time, retrieving tweet text and metadata for analysis.
This project requires installing xampp, install it from here. It comes with MySQL installation as well so you don't have to install it seperately.
Before creating the app, make sure to create a "user" databse in MySQL with 3 columns (name, email id and password).
To set up a basic flask app, refer to Create flask App.
Create app.py file, this will be our main flask app. In this file we establish a connection to our SQL database using the 'conn' object and also set a user cookie variable, which checks if the user has logged in, before redirecting him/her to the home page. This script also handles the user input on the login/register pages.
Breakdown:
Imports & Setup
Database Connection
Routes
This file takes user input (a keyword and tweet count), fetches live tweets via the Tweepy API, cleans and analyzes them for sentiment (from -1 for negative to 1 for positive) and then creates a pie chart saved as an image for later display in HTML pages.
Explanation:
Tweet Fetching & Sentiment Analysis
Data Processing & Visualization
Routes
Templates in flask contains all the HTML files for the flask app. Let's look at the HTML files we need to create for this project one by one-
HTML code for the page that displays the login form. The user enters a username and password, which has validations. Once the data is validated, these variables are passed to the main.py file, which connects to the SQL database to check if the login is valid.
HTML code for the page that displays the registration form. The user enters a username and password, which has validations. Additionally, the user's name becomes a value for the cookie that is set in the main.py file.
Once the data is validated, these variables are passed to the main.py file, which connects to the SQL database to check if the login is valid.
HTML home page. The page has 2 main parts
This template asks the users to enter a topic/word of their interest and the number of tweets based on that topic that users would like to analyze.
Please note that Twitter has daily and hourly rate limits, which cannot be exceeded.
This form passes the data to second.py file, which calculates the output and sets "jinja" variables. (Jinja allows passing values between python and HTML).These variables then display the output to users.
This HTML template simply displays an image file saved in our project. This image file is generated in the second.py file code. The image is a Pie Chart, which visually represents the results of sentiment analysis. The image is overwritten every time the code is run.
To run the flask application, use this command in terminal-
python app.py
And then uprn the development URL in a browser= "http://127.0.0.1:5000"
Note: Since March 2023, Twitter’s search endpoints require a paid plan (e.g., Basic tier, $100/month). The Free tier no longer supports searching tweets, so this app’s search feature won’t work without a subscription.