Stack: TwitterAPI + Flask + Nameko + Postgresql + Textblob
- It receives POST request with instruction of which twitter it needs to collect
- Then it opens socket connection with Twitter API and starts to receive real time twitter data
- Each tweet assigned with it sentiment score with help of TextBlob
- All data then goes to PostgreSQL database
- Because it uses Nameko and RabbitMQ you can asynchronously run many different tasks and collect different topics.
- Because it based on Flask you can easily connect this with other services that will communicate with this service by POST requests
- For each tweet service assign sentiment score using TextBlob and store it to the PostgreSQL so latter you can perform analysis on that.
- It scalable and expandable - you can easily add other sentiment analysis tools or create visualization or web interface because it based on Flask
{
"duration": 60,
"query": ["Bitcoin", "BTC", "Cryptocurrency", "Crypto"],
"translate": false
}
where duration is how many minutes you what collect streaming twitter data, query is list of search queries that Twitter API will use to send you relevant tweets, translate is boolean in case False will collect only english tweets, otherwise service will try machine translation from TextBlob
- Clone or download this repository
- Create virtual environment and install dependencies
cd twitter_sentiment_analysis_microservice
virtualenv env --python python3
source env/bin/activate
pip install -r requirements.txt
-
Setup PostgreSQL Please find instruction here
-
Get your Twitter credentials You can get your Twitter credentials here
-
Install RabbitMQ: instruction for mac: https://www.rabbitmq.com/install-homebrew.html
-
Start RabbitMQ:
sudo rabbitmq-server
-
Start Nameko:
nameko run service --config ./config.yaml
-
Run Flask (in a different terminal):
python app.py
Now it ready to receive requests:
By default you can send POST requests to 127.0.0.1:5000/collect