Make a light that flashes each time a certain phrase is tweeted.
Firstly if you don’t have a twitter account register for one for free at twitter.com. In order to create apps that interact with twitter you need to register your apps with Twitter. To do this, go to dev.twitter.com and sign into your Twitter account.
Once you have signed in, at the bottom of the page, under the “Tools” column click on “Manage Your Apps”.
Then click on the button “Create New App”.
The next page involves giving twitter some information about your app. For this project you don’t need to fill in the Callback URL.
Name - is the name of the app
Description - what the app does
Website - include a generic webpage as a placeholder. I used my home screen of my facebook. It’s important to use the http:// version of this webpage’s address.
Then read and agree to the terms and conditions.
You will now need to adjust permissions so that you can use your Twitter account for the project.
Go to the “Permissions” tab. Under “Access” change from “Read” only to “Read and Write” and then click “Update Settings”.
Now go to the “Keys and Access Token” tab and at the bottom of the page click “Create my access token”. You will then have a page with all of the information from Twitter that you need to make the program for this project work.
There are four unique codes on this page.
Consumer Key (API Key)
Consumer Secret (API Secret)
Access Token Secret
Make a note of these unique codes.
A Raspberry Pi
Usual Raspberry Pi peripherals - mouse, screen, keyboard, power cable, ethernet cable
An additional power supply for Pibrella
Set of battery powered fairy lights - pick ones with low voltage so only running off two AA batteries.
Soldering iron (optional)
If you aren’t sure if it is really working. Change the phrase love or robots to a nonsense word e.g. ‘hellloooooowwwweee’ and then get a friend to tweet the non-sense word/phrase and you should see your program respond by printing ‘They are talking about this’
Only attempt this project with battery powered fairy lights that run off a low voltage. If you don’t want to cut up or desolder your fairy lights you can also do this project by connecting one or more LEDs (multiple in parallel) with a resistor and connecting these to output e of the Pibrella Board.
Finally, have fun thinking about what other things you could connect to pin e on the Pibrella. It will give approximately a 3V output so can run small motors and solenoids. What other twitter bots could you build with this basic Twitter searching program?
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Streamimport sys, subprocess, urllib, time, tweepy
#enter the corresponding information from your Twitter application:
CONSUMER_KEY = ‘___________________’#keep the quotes, replace this with your consumer key
CONSUMER_SECRET =‘____________________’#keep the quotes, replace this with your consumer secret key
ACCESS_TOKEN = ‘_____________________’#keep the quotes, replace this with your access token
ACCESS_SECRET = ‘_________________ ’#keep the quotes, replace this with your access token secret
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
)api = tweepy.API(auth)
def on_data(self, data):
print 'They are talking about this’
def on_error(self, status):
if __name__ == '__main__':
l = StdOutListener()
auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
stream = Stream(auth, l)
#this searches for robots and when that is found it flashes the LEDs which are attached to pin e on the pibrella and it returns the phrase They are talking about this