- Notifications
You must be signed in to change notification settings - Fork20
A Python based bot for Raspberry Pi that grabs tweets with a specific hashtag and reads them out loud.
License
jpescada/TwitterPiBot
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A Python based bot for Raspberry Pi that grabs tweets with a specific hashtag and reads them out loud.
It was a quick side project that served as a good learning exercise for me. As this was a side project, I've set a limit of 2 days to get it done. Yes, it is sort of hacked together and could use a bit of refactoring. But it still handled the top trending hashtag #StarWars for 24 hours, without breaking. So, it's stable (enough) and working fine. (famous last words?)
This python app connects to Twitter Streaming API and captures tweets with a specific hashtag. Those captured tweets are then processed and stored in a local SQLite database that works like a queue. And lastly (every few seconds), a tweet is picked from that queue and ran through a text-to-speech engine converting the tweet into audio, that is played out through speakers connected to the audio jack.
To run, it uses a good chunk of 3rd party modules, such as:
- Peewee (to manage models and an SQLite database)
- Tweepy (to access Twitter API)
- Flite (to synthetise speech from tweets)
Essentially, a Raspberry Pi (running Debian) with a USB Wifi dongle attached (and connected to the internet). Then you need some source of power (such as a USB portable battery pack) and one or two speakers connected to the 3.5mm audio jack.
To run the instructions below, you have two options (that I can remember):
- plug your Raspberry Pi to a screen, mouse, keyboard and run in the terminal
- connect to your Raspberry via SSH from your computer and run it remotely (which is waaay cooler!)
I recommend the second option. And if you go with the second option, I also recommend usingscreen
in SSH to allowresuming your session without having to leave an SSH window open. To installscreen
run the following in terminal:
$ sudo apt-get install screen
Ok, so first things first: you need to create a Twitter app to use their API. Go tohttps://apps.twitter.com and create a new app. Once that is done, under the "Keys and Access Tokens" tab also generate an Access Token.
Now, let's make sure your Raspberry Pi is up-to-date. In terminal run the following two commands:
$ sudo apt-get update
$ sudo apt-get upgrade
And one (more) package to install:Flite, the text-to-speech engine that we'll be using. Run this:
$ sudo apt-get install flite
Start by cloning this repository to your Raspberry Pi:
$ git clone https://github.com/jpescada/TwitterPiBot.git
Go into that new folder:
$ cd TwitterPiBot/
Make surepip
is up to date:
$ sudo pip install -U pip
And install the python modules required for this app (Peewee andTweepy):
$ sudo pip install -r requirements.txt
Just one last thing to do before running it for the first time. Open theconfig.py
file in the root folder to update the Twitter API credentials and the hashtag to search for:
$ sudo nano config.py
When you're done, hitCtrl+X
to close and save the file.
Just type the command:
$ python main.py
If everything went according to plan, it should connect to Twitter start collecting tweets and reading them out loud every 30 seconds.
To exit, hitCtrl+C
.
In terminal, run the command:
$ alsamixer
Then use keyboardup
anddown
keys for volume,m
key to mute andesc
key to exit.
What bugs? :) If you found any issues, please report it in theIssues or, if you can fix it, submit aPull request. Thank you!
The original idea behind this project came from a client request (who later dropped it), but it's based onHugo the Twitter-Powered Robot byPaper Leaf.