Skip to content

Politweets scrapes UK politician tweets using the Twitter API & Tweepy. Sentiment analysis applied via Textblob and presented using Streamlit.

Notifications You must be signed in to change notification settings

ChristopherBacon/Politweets

Repository files navigation

Politweets

Politweets scrapes UK politician tweets using the Twitter API & Tweepy. Sentiment analysis applied via Textblob and presented using Streamlit.

Preview

Table of Contents

Installation

  1. Start by cloning the repository:
git clone https://github.com/ChristopherBacon/Politweets.git
cd politweets
  1. Create a python 3.7.3 environment.

  2. 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

Data

  1. politweets.csv The csv containing all of the scraped tweets, with polarity and subjectivity features

  2. 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

Code

  1. twitter_api.py Contains the functions to access Twitter API and scrape data with Tweepy. Finally saving the data to politweets.csv

  2. twitter_handles_list.py Functions to clean Twitter handles and create politcal party column

  3. TweepyMPs.py Polarity, Subjectivity and design functions along with the bulk of the Streamlit code to format display properties

Conclusion

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.

About

Politweets scrapes UK politician tweets using the Twitter API & Tweepy. Sentiment analysis applied via Textblob and presented using Streamlit.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages