Politweets scrapes UK politician tweets using the Twitter API & Tweepy. Sentiment analysis applied via Textblob and presented using Streamlit.
- Start by cloning the repository:
git clone https://github.com/ChristopherBacon/Politweets.git
cd politweets
-
Create a
python 3.7.3
environment. -
Install dependencies
pip install requirements.txt
If you want to scrape your own tweet data you will need to register for a twitter API key and register your project. The code that is commented out contained in: twitter_api.py, you can follow a tutorial and register for an API here.
To view the data in Streamlit:
streamlit run TweepyMPs.py
You can also access helper functions to investigate the data further in the module: twitter_handles_list.py and TweepyMPs.py
-
politweets.csv
The csv containing all of the scraped tweets, with polarity and subjectivity features -
MPs_twitter.csv
The csv containing all of the MPs twitter handles as used with Tweepy when scraping tweets. Party data also used. This is a great resource downloadable from Politics Social
-
twitter_api.py Contains the functions to access Twitter API and scrape data with Tweepy. Finally saving the data to
politweets.csv
-
twitter_handles_list.py Functions to clean Twitter handles and create politcal party column
-
TweepyMPs.py Polarity, Subjectivity and design functions along with the bulk of the Streamlit code to format display properties
It was great to pull together three key data skills for this project; accessing and scraping data via an API, doing some NLP using Textblob library and presenting via a new data app framework. I learnt alot in undertaking this project. There is scope to extend this project and do more indepth analysis on the sentiment of the tweets, and see what effect cleaning might have on the tweet data. I could also test the results against other NLP libraries.