I'm creating a project using a Raspberry Pi and a berry clip. So what I've programmed it to do is (using twython) the code searches for twitters with a particular keyword the user enters and when it finds it, it shows you the tweet and the LED flash. I want to expand this on my berry clip and use all 6 LEDs with 6 different keywords. I managed to program it to search for 6 keywords but so far I can't find out how to make each led depending the keyword. For example if the stream finds the 1st keyword the first LED will flash. If it finds the 2nd keyword then the 2nd LED will flash,etc,etc. I tried using if statements inside the first if statement (if 'text' in data:
) by adding if TERMS in 'text':
but it didn't work. This is my code so far:
#!/usr/bin/python
import time
import RPi.GPIO as GPIO
from twython import TwythonStreamer
ledList=[4,17,22,10,9,11]
GPIO.setmode(GPIO.BCM)
GPIO.setup(ledList,GPIO.OUT)
TERMS=(raw_input("Please type the first keyword"));
TERMS2=(raw_input("Please type the second keyword"));
TERMS3=(raw_input("Please type the third keyword"));
TERMS4=(raw_input("Please type the fourth keyword"));
TERMS5=(raw_input("Please type the fifth keyword"));
TERMS6=(raw_input("Please type the sixth keyword"));
termsList=[TERMS,TERMS1,TERMS2,TERMS3,TERMS4,TERMS5,TERMS6]
APP_KEY='xxxxxxxxxxxx'
APP_SECRET='xxxxxxxxx'
OAUTH_TOKEN='xxxxxxxxx'
OAUTH_TOKEN_SECRET='xxxxxxxxx'
class streamer(TwythonStreamer):
def success(self,data):
if 'text' in data:
tweet_data=data['text'].encode('utf-8')
print (tweet_data)
GPIO.output(4,True)
time.sleep(1)
GPIO.output(4,False)
try:
stream = streamer(APP_KEY,APP_SECRET,OAUTH_TOKEN,OAUTH_TOKEN_SECRET)
stream.statuses.filter(track=termsList)
except KeyboardInterrupt:
print ('ending')
GPIO.cleanup()